2011年3月27日 星期日

P5的基本繪圖_8 mouse-follow


int num = 60;
int[] x = new int[num];
int[] y = new int[num];

void setup() {
  size(240, 240);
  smooth();
  noStroke();
}

void draw() {
  background(0);
  // Copy array values from back to front
  for (int i = x.length-1; i > 0; i--) {
    println(i);
    x[i] = x[i-1];
    y[i] = y[i-1];
  }
  x[0] = mouseX; // Set the first element
  y[0] = mouseY; // Set the first element
  for (int i = 0; i < x.length; i++) {
    fill(i * 4);
    ellipse(x[i], y[i], 40, 40);
  }
}




download pd file