Wednesday, October 2, 2013

Array Example - Dog 3000

float[] x = new float[3000];
float[] y = new float[3000];
PImage dog;

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

void draw() {
  background(0);
  for (int i = 0; i < 3000; i++) {
    image(dog, x[i], y[i], 40, 40);
    x[i]+=1;
    y[i]+=1;
    if (x[i] > width) {
      x[i] = random(-1000, 0);
    }
    if (y[i] > height) {
      y[i] = random(-1000, 0);
    }
  }
}

 //YOU WILL NEED THE DOG IMAGE IN YOUR DATA FOLDER FOR THIS CODE TO RUN

No comments:

Post a Comment