Modify a text file: $/39/p31a.java
$/39/p31a.java
///// Practice Oct. 2 String title="Practice Oct. 2", author="BAM"; float x=400, y=300, w=50, h=80; float sealevel=100, waveSize=20, waveSpacing=20; float buttonX, buttonY; int r=200,g=50,b=200; color skyColor=color(200,220,255); color seaColor=color(50,200,250); color grassColor=color(0,150,50); boolean debug=false; void setup() { //// Init. size(800,600); buttonX=width-200; buttonY=height-100; } void draw() { //// Next frame scene(); action(); } void scene() { //// sky, sea, grass, button, etc. background( 200,220,255 ); fill(0); textSize(20); text( title, 300, 20 ); textSize(12); text( "? for help", 300, 40 ); if (key == '?') help(); // Sea noStroke(); fill( seaColor ); // Greenish sea. rectMode(CORNERS); rect( 0, sealevel, width, height ); rectMode(CORNER); grass(); waves(); // Button fill( 255,200,200 ); stroke(0); rectMode( CENTER ); rect( buttonX, buttonY, 150, 50 ); fill(0); text( "CLICK", buttonX-50, buttonY-10 ); text( "to move octopus", buttonX-50, buttonY+10 ); } void help() { //// Instructions int n=2; fill(100,0,0); text( "Click octopus to change color", 500, 12*n++ ); text( "Click button to move octopus", 500, 12*n++ ); text( "~ to change waves", 500, 12*n++ ); text( "@ for debugging", 500, 12*n++ ); text( "----", 500, 12*n++ ); text( "@ for debugging", 500, 12*n++ ); } void grass() { //// float grassX=10, grassX2=10, grassSkip=20; while ( grassX < width) { strokeWeight( 4) ; stroke( grassColor ); line( grassX,height-50, grassX2, height-5 ); grassX= grassX + grassSkip; grassX2= grassX2 + grassSkip; } } void waves() { //// Waves at sealevel float p=10, dp=(waveSpacing+waveSize)/2; while (p
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=='@') debug = ! debug; if (key=='~') { waveSize = random(15,50); waveSpacing = random(15,50); } }