//boat float boatX=200, boatY=225, boatDX=1; ///waves //-- float wavesX=0, wavesY=240, wavesDX=2; float wavesStart=0; //button to move octopus float buttonX=50, buttonY=50; float bh=50, bw=100; ///octopus float octopusX=400, octopusY=500; float octopusDX=2, octopusDY=2; float w=50, h=65; int r=200,g=50,b=200; void setup(){ size(700,700); } void draw(){ //brings up help screen if (key=='?'||key=='/'){ help(); }else{ scene(); action(); } } void action(){ octopus(); boat(); button(); } void help(){ text("MICHAEL HOTETZ",width/2-50,50); text("PROJECT NUMBER THREE",width/2-75,80); } void scene(){ //sky background(140,214,240); //sea rectMode(CORNER); fill(28,185,153); rect(0,250,800,600); fill(0); text("PRESS ? FOR HELP",50,150); grass(); waves(); } void mousePressed(){ //changes octopus color when clicked if (hit(octopusX,octopusY,w,h)){ r= int( random( 100, 250) ); g= int( random( 0,100 )); b= int( random( 100, 250)); } //changes x and y values of octopus when button is clicked if ( hit( buttonX,buttonY, bw,bh ) ){ octopusX=random(50,width-50); octopusY=random(300,height-50); } } ///creates boolean boolean hit( float x, float y, float w, float h) { //// Return true iff mouse within rect at x,y boolean result=true; float top= y - h/2, bottom=y+h/2, left=x-w/2, right=x+w/2; if (mouseX < left ) result= false; if (mouseY > right ) result= false; if (mouseY < top ) result= false; if (mouseY > bottom ) result= false; return result; /* mouseX > X-w/2 && mouseX < X+w/2 && mouseY > Y-h/2 && mouseY < Y+h/2 ; */ } void octopus(){ ////bounce off walls octopusX+=octopusDX; octopusY+=octopusDY; if (octopusX>width-20||octopusX<25){ octopusDX*=-1; } if (octopusY>height-50||octopusY<315){ octopusDY*=-1; } ////draws octopus fill(r,g,b); rectMode(CENTER); noStroke(); //body rect(octopusX,octopusY,50,40); ellipse(octopusX,octopusY-20,50,50); //legs that moves dependent on direction strokeWeight(7); stroke(r,g,b); //moves legs back and forth //@bam 6 legs looked and fit nicer, input 6.25 instead of 12.5 for 8 legs //might also have to lower strokeWeight for (float l=octopusX-20;(lwidth-100 || boatX<100){ boatDX*=-1; } ///boats hull //vibrates boat with water arc(boatX,boatY-random(1),200,100,0,PI); ///flag pole stroke(82,59,34); strokeWeight(10); line(boatX,boatY,boatX,boatY-100); ///reset stroke noStroke(); //flag fill(255); if (boatDX==1){ triangle(boatX+10,boatY-100,boatX+10,boatY-10,boatX+100,boatY-10); }else{ triangle(boatX-10,boatY-100,boatX-10,boatY-10,boatX-100,boatY-10); } } void waves(){ ///creats wave that vibrate accross the screen float wavesX=0, wavesY=240, wavesDX=-2; if (frameCount % 10 == 0) wavesStart= (wavesStart+1) % 50; wavesX = wavesStart - 50; text( wavesStart, 10,10 ); while(wavesX < width+50){ fill(140,214,240); stroke(7,108,51); arc(wavesX,wavesY-random(1),50,50,0,PI); wavesX= wavesX+50; } } void grass(){ strokeWeight(4); stroke(70,131,52); ////makes grass move sway dependent on octopus direction int g=0; while (g