int n; //# of bird pairs float x, y; //position float w , h; //bird size float horizon=500; String myName = "Adam Kochen"; String gName = "Flock"; void setup () { size(800,600); reset(); } void draw() { background(200,250,255); //sky //0-0 x = 600; //0-0 y = 300; //0-0 if(x-60*n < width){ x += random(20); //0-0 } y = y-random(1,5)+random(1,5); w= 30; h= 20; flock(n,x,y,w,h); if(x-60*n > width){ reset(); } //test text fill(0); text("n "+n,10,10); text("x "+x,10,20); text("y "+y,10,30); text("w "+w,10,40); text("h "+h,10,50); text(myName + " - " + gName,300,10); } void bird(float x,float y,float w,float h ) { //draw lead bird triangle triangle(x,y,x-w,y-h/2,x-w,y+h/2); } void flock(int n,float x,float y,float w,float h){ //followers float xx = x; float yy = y; float dy = w/200; float dx = h/5 ; float ww = w; float hh = h; for( int l = 1; l < n ; l++){ bird( xx,y-dy, ww,hh ); // above bird( xx,y+dy, ww,hh ); // below // shrink bird hh *= 0.9; ww *= 0.95; //birds above and below xx= xx - 2*w; dy = dy + h; } } void reset() { // reset n = int (random(4,7)); x= random(0,50); y= random(0,horizon); w= 50; h= 20; } void keyPressed() { // keys if (key == 'r') reset(); }