//Tristan Szakacs //Project Three //Project Two but revamped Button b1, b2; Fish f1, f2, f3; float cloudX = 20, cloudY = 20, cloudDX = 0.4, cloudDY = 0.2; float surface = 200; int fishX, fishY; void setup() { size( 800, 800); b1= new Button( "Go", 0, 0, 150, 50, 150); b2= new Button( "Fish", 150, 0, 150, 50, 150); f1= new Fish( "Nikki", fishX - 100, fishY - 100, 250, 100, 250); f2= new Fish( "Mike", fishX - 100, fishY - 100, 100, 250, 100); f3= new Fish( "Cliff", fishX - 100, fishY - 100, 150, 50, 200); mousePressed(); keyPressed(); } void draw() { background( 50,100, 200); cloud( cloudX, cloudY); b1.show(); b2.show(); drawSea(); goFish(); } //EVENTS again.. void goFish() { f1.show(); f2.show(); f3.show(); f1.animate(); f2.animate(); f3.animate(); } void initialize() { f1.reset(); } void keyPressed() //Has to be put into Setup because if reset function is placed in draw it occurs every frame... { if( key == 'g' || key == 'G') { f1.reset(); f2.reset(); f3.reset(); } } void mousePressed() //Has to be put into Setup because if reset function is placed in draw it occurs every frame... { if( b1.clicked(mouseX, mouseY) == true) { f1.reset(); f2.reset(); f3.reset(); } } //ENVIRONMENT that does not need to be duplicated. void drawSea() //Draws the sea. { fill( 0, 90, 30); rect( 0, 200, 800, 600); } void cloud( float x, float y) //Draws AND animates the cloud. { fill( 250); ellipse( x, y, 100, 50); ellipse( x-30, y-20, 60, 30); cloudX= cloudX + cloudDX; if( cloudX < 0) cloudDY *= -1; if( cloudX > 800) cloudDX *= -1; cloudY= cloudY + cloudDY; if( cloudY < 0) cloudDY *= -1; if( cloudY > 150) cloudDY *= -1; } //CLASSES// class Button //Class used to create all buttons. { float x,y; float w=80, h=30; String s; int r,g,b; boolean action; //CONSTRUCTORS// Button( String s, float x, float y) //Bread and butter constructor with size and text dummy variables. { this.s= s; this.x= x; this.y= y; } Button( String s, float x, float y, int r, int g, int b) //This Constructor allows you to enter color values. See button instantiation. { this.s= s; this.x= x; this.y= y; this.r= r; this.g= g; this.b= b; } //FUNCTIONS// void show() //Method to configure everything that will get displayed. Keeps the draw method clean. { fill(r,g,b); strokeWeight(3); rectMode(CORNER); rect( x,y, w, h, 100); //The last parameter is the one that rounds the edges of buttons. strokeWeight(1); //Strokeweight for text?? fill(0); //Text color text( s, x+10, y+20 ); //Centers the text. S is the text entered w the instance. } boolean clicked( float xx, float yy) { if(xx > x && xx < x+w && yy > y && yy < y+h) { return true; } return false; } } class Fish //Class used to create all fish. { float x, y; float dx, dy; float w= 100; float h= 50; String name; int r, g, b; //CONSTRUCTORS// Fish( String name, int x, int y, int r, int g, int b) { this.name= name; this.x= x; this.y= y; this.r= r; this.g= g; this.b= b; } //FUNCTIONS// void show() { fill( r, g, b); triangle( x-75, y+15, x-50, y, x-75, y-15); //Tail ellipse( x, y, w, h); fill(0); text( name, x-40, y); fill(250); ellipse( x+25, y-5, 5, 5); //Eye. } void animate() { int position= int(x)/100; if( position % 2 == 0) { triangle( x, y, x+20, y, x+10, y+20); } else { triangle( x, y, x+20, y, x+10, y-20); //Animates Fins. } x += dx; //Causes fish to move and reset when it goes over edge. if( x > 800) { x= 0; y= random( 200, 800); dx= random( 1, 8); } } void reset() { x= 0; y= random( surface, height); dx= random( 1, 8); } } class Boat //Class to create boats... { //Constructors// }