Wednesday, October 2, 2013

Array Example - 3000 spoon

PImage spoon;
float[] xPos = new float[3000];
float[] yPos = new float[3000];

void setup() {
  size(500, 400);
  fill(255,200);
  spoon = loadImage("spoon.png");
  for (int i = 0; i < 3000; i++) {
    xPos[i] = random(-1000,500);
    yPos[i] = random(-1000,500);
  }
}

void draw() {
  background(0);
  for (int i = 0; i < 3000; i++) {
    image(spoon,xPos[i], yPos[i], 50, 50);
    xPos[i]+=2;
    yPos[i]+=2;
    if(xPos[i] > width){
      xPos[i] = random(-1000,0);
    }
    if(yPos[i] > width){
      yPos[i] = random(-1000,0);
    }
  }
 
 
}
// YOU WILL NEED THE SPOON IMAGE IN THE DATA FOLDER FOR THIS TO RUN

No comments:

Post a Comment