//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(0); 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)); rect(20,20,60,80); rect(30,-10,40,40); fill(random(0,255),random(0,255),random(0,255)); ellipse(50,10,20,20); ellipse(50,10,random(5,15),random(5,15)); fill(random(0,255),random(0,255),random(0,255)); rect(80,50,-40,20); rect(30,50,-40,20); rect(25,140,20,-40); rect(55,140,20,-40); } //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<=100000) { pushMatrix(); translate(i+tx,ty); drawFish(); popMatrix(); i=i+100; } //update my variables - either randomly update y or use sin tx = tx - 2; //ty = ty + int(random(-5, 5)); ty = 25 + int(5*sin(tx/50.0*6*PI)); }