//very simple program of animating fish that "swims" across the screen //variables to move the fish int tx, ty; //a function to set up the general drawing parameters void setup() { size(400, 200); background(#579D5F); smooth(); tx = 400; ty = 100; frameRate(20); } //press any key to reset the fish void keyPressed() { tx = 400; ty = 100; } //function to draw the fish void drawFish(){ fill(random(0,255),random(0,255),random(0,255)); stroke(0); ellipse(-100, 0, 30, 10); triangle(-85,0, -70, 10, -70, -10); stroke(255); fill(0); rect(-110, -3, 4, 2); fill(random(0,255),random(0,255),random(0,255)); stroke(0); ellipse(0, 0, 70, 30); triangle(25, 0, 38, -20, 38, 20); stroke(255); fill(242,242,242); ellipse(-15,-5,10,5); fill(0); ellipse(-15,-5,5,3); fill(random(0,255),random(0,255),random(0,255)); ellipse(-20,5,random(5,15),random(5,15)); } //the draw function - which will loop void draw() { int i; i = 0; background(0); //draw the fish in an updated position using variables while (i <= 7500) { pushMatrix(); translate(i + tx,ty); drawFish(); popMatrix(); i = i+170; } //update my variables - either randomly update y or use sin tx = tx - 1; //ty = ty + int(random(-5, 5)); ty = 75 + int(50*sin(tx/200.0*6*PI)); }