color skyColor=color(200,220,255); color seaColor=color(105,242,232); color grassColor=color(0,150,50); float sealevel=245, waveSize=20, waveSpacing=20; float buttonX, buttonY; float x=400, y=300, w=70, h=90; float dx=2, dy=1; float wavesX=0,wavesY=240,wavesDX=2; float wavesStart=0,wavesSize=50; float subX=300,subY=245,wI=200,hI=150; int r=200,g=50,b=200; void setup() { size (700,700); buttonX=width; buttonY=height; } void draw(){ scene(); subaction(); } void scene() { background (140,214,240); noStroke(); fill(seaColor); rectMode(CORNERS); rect(0,sealevel,width,height); rectMode(CORNER); grass(); sun(); waves(); } void grass() { float grassX=10,grassSpace=20; while (grassXwidth-50) ? -dx : dx; dy= (yheight-100) ? -dy : dy; x += dx; y += dy; } sub (); } //// Draw the octopus void octopusDraw( float x, float y ) { noStroke(); fill( r,g,b ); rectMode(CENTER); rect( x, y, w, h ); ellipse( x, y-h/2, w, w); fill(255,255,0); ellipse( x+dx*5, y-13-h/2, 12,12 ); fill(255,0,0); ellipse( x+dx*5, y-13-h/2, 3,3 ); //// Legs float legX=x-w/2, legY=y+h/2; for (int j=0; j<8; j++) { leg( legX, legY ); legX += w/8; } }// octopusDraw() // void leg( float x, float y ) { //// Draw a leg stroke(255,0,255); strokeWeight(3); line( x, y, x-2*dx+random(2), y+20 ); } void mousePressed() { //// Click event if ( hit(x,y,w,h) ) { background(0); r= int( random( 100, 250) ); g= int( random( 0,100 )); b= int( random( 100, 250)); } if (hit(buttonX,buttonY, 150,40)) { //-- background(0,255,0); x= random(50,width-50); y= random(sealevel,height-50); } } boolean hit( float x, float y, float w, float h ) { //// True if mouse hit this rect return mouseX > x-w/2 && mouseX < x+w/2 && mouseY > y-h/2 && mouseY < y+h/2 ; } void keyPressed() { //// Key handler if (key=='q') exit(); if (key=='~') { waveSize = random(15,50); waveSpacing = random(15,50); } }