//Tristan Szakacs //Project Three //Project Two but revamped Button b1, b2; Fish f1; float cloudX = 20, cloudY = 20, cloudDX = 0.4, cloudDY = 0.2; 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( "Steve", } void draw() { background( 50,100, 200); cloud( cloudX, cloudY); b1.show(); b2.show(); drawSea(); } //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= random(50, 100); float h= random(50, 100); String name; int r, g, b; //CONSTRUCTORS// Fish( String name, float x, float 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() { float position= (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( 200, 800); dx= random( 1, 8); } }