class Fish { // Fish swimming // float x = 100, y = 100, dx = 3, dy = 0, w = 80, h = 30; String name = "Object Based Fish"; void show() { // Draw fish // fill(100, 100, 255); ellipse( x , y, w, h ); float front = x + w/2, back = x- w/2; if ( dx > 0 ) { triangle( back, y, back-20, y-10, back-20, y+10 ); } else { triangle( front,y, front+20, y-10, front+20, y+10 ); } float eye; eye= ( dx > 0 ) ? front - 20 : back + 20; fill(255); // eye strokeWeight(3); fill (200); ellipse( eye, y -12, 10, 10 ); ellipse( eye, y -15, 10, 10 ); text( name, x-10, y ); } void move() { //... if (x > 700 || x < 100) dx=-dx; if (y > 500 || y < 100 ) dy=-dy; dy= dy + random( -1, +1 ); if (abs(dy) > 5) dy /= 15; x += dx; y += dy; } boolean isHit( float x, float y ) { // Return true if (x,y) is within this fish! if (x < this.x - w/2 || x > this.x+w/2) return false; if (y < this.y - h/2 || y > this.y+h/2) return false; return true; } //// constructor //// Fish() {}; Fish( String sam ) { name=sam; restart(); } void restart() { x= random (left, right); // random position y= random (top, bottom); dx= random (1, 7); // random position dy= 0; w= random(20,120); // random size h= random(20,50); fill(255,100,0); } } String title=" Fish "; float left = 50, top = 50, right = 750, bottom = 550; Fish sammy; int many = 0; // ONE FISH // Fish [] school; // void setup() { // Setup screen // size( 800, 600 ); reset(); } void reset() { // Reset everything. sammy= new Fish(); sammy.name= "Sammy"; // Array of Fish // school= new Fish[many]; for (int j = 15; j 50 ) text( many + " fish", width-65, 20 ); // Tank fill ( 0, 175, 255 ); rectMode ( CORNERS ); rect ( left - 10 , top + 5, right + 15, bottom + 15 ); // bottom of fish tank // fill(125); rectMode ( CORNERS ); rect ( 20, 520, 785, 575 ); } void showAll() { // Show fish sammy.show(); for (int j=10; j < many; j++) { school [j].show(); } } void action() { // Move fish. sammy.move(); for (int j = 20; j < many; j++) { school [j].move(); } collisions(); } void collisions() { // ++++ }