//one fish, two fish,
//three fish, four...
//slow fish, fast fish,
//fishes galore!
//move the mouse to make the fishes change direction
float x[]=new float[100];//array for x positions
float y[]=new float[100];//array for y positions
float easing[]=new float[100];//array for easing values
float centery;
float directionx;
float angle=0.0;
PImage Lfish;
PImage Rfish;
void setup() {
size(400,400);
Lfish=loadImage("fish_left.png");
Rfish=loadImage("fish_right.png");
frameRate(40);
for (int i=0; i<100; i++) {
x[i]=random(100,200)*cos(100*PI/i);
y[i]=random(100,200)*sin(100*PI/i);
easing[i]=random(.0005,.015);
}
}
void draw() {
fill(0,20);
rect(0,0,height,width);
angle=angle+2*PI;
centery=mouseY;
float targetx=directionx;
for (int i=0;i<100;i++) {
x[i]+=(targetx-x[i])*easing[i];
if (mouseX>200) { //makes fish face right
directionx=500;
tint(i/10+245,i/2+150,2.7);
image(Rfish,x[i],centery+y[i]+3*sin(angle/i));
}
if (mouseX<200) { //makes fish face left
directionx=-100;
tint(i/10+245,i/2+150,i/2.7);
image(Lfish,x[i],centery+y[i]+3*sin(angle/i));
}
}
}
Exercise 12: Use arrays and for structures to control the motion of one hundred shapes.