class Fish { // Fishes swim float x=200,y=200, dx=5, dy=.30, w=80,h=30; int r,g,b; // Color String name=""; // METHODS // void show() { // Draw the fishes. fill(r= 100,g=8,b=90); ellipse( x,y,w,h ); float front=x+w/2, back=x-w/2; triangle( back,y, back-20,y-10, back-20,y+10 ); // Tail fill(155); // eye strokeWeight(5); ellipse( front-15, y-10, 10, 10 ); fill(r= 100,g=8,b=90); ellipse( x,y,w,h ); // makefloat triangle( back,y, back-20,y-10, back-20,y+10 ); // Tail fill(155); // eye strokeWeight(5); ellipse( front-15, y-10, 10, 10 ); } void move() { //move the fishes if (x>right) dx= -dx; if (x>left) dx= +dx; if (y>top) dy= +dy; if (y>bottom) dy= -dy; dy= dy + random( -1, +1 ); x += dx; y += dy; } boolean hit( float x, float y ) { // boolean/if/return true statement if (x < x-w/2 || x > x+w/2) return false; if (y < y-h/2 || y > y+h/2) return false; return true; // Hit detected. } } //END class Fish // "Button" class class Button { // Button } // GLOBALS: String title="Fish project"; String news="r to reset; e to exit"; float left=50, top=50, right=550, bottom=350; Button b1; // Fish charlie; // Declare the object // // void setup() { // Setup screen; instantiate object(s). size( 600, 400 ); reset(); } void reset() { // Reset everything. // charlie= new Fish(); charlie.name= "Charlie"; // Instatiate it. // // b1= new Button(); } // void draw() { // Next frame scene(); // background, tank, etc. showAll(); // Draw the fish, buttons, etc. action(); // Move fish, check collisions, etc. } void showAll() { // Show fish, buttons, etc. charlie.show(); // b1.show(); } void action() { // Move fish. charlie.move(); } void scene() { // Tank background( 55, 255, 55 ); } // EVENT HANDLERS void keyPressed() { //// Handle keys. if (key == 'e') exit(); if (key == 'r') reset(); }