2012年3月11日 星期日

homework5-2 (97473011 Alvin)

















/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
I was learning how to use arrays and applied it to the program to express various colors.

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

int num = 50;
int[] x = new int[num];
int[] y = new int[num];
int r,g,v;
void setup() {
size(300, 300);
noStroke();
smooth();
fill(255, 102);
}
void draw() {
background(0);
// Shift the values to the right
for (int i = num-1; i > 0; i--) {
x[i] = x[i-1];
y[i] = y[i-1];
}
// Add the new values to the beginning of the array
x[0] = mouseX;
y[0] = mouseY;
// Draw the circles
for (int i = 0; i < num; i++) {
  r=int(random(255));
  g=int(random(255));
  v=int(random(255));
 
  fill(r,g,v);
ellipse(x[i], y[i], i/2.0, i/2.0);
}
}

沒有留言:

張貼留言