///// MODULARIZED. String title="Modularized",author="BAM"; float horizon; float sunX, sunY, dogX, dogY; //// SETUP: size & modes void setup() { size( 600, 400 ); horizon= height/3; sunX=0; sunY=50; } // NEXT FRAME: scene, action, etc. void draw() { scene(); action(); show(); messages(); } //// Scene: sky & grass void scene() { background( 150,200,250 ); // blue sky fill( 100,255,100 ); // green grass rect( 0,horizon, width,height-horizon ); fill( 255,255,0 ); // sun ellipse( sunX,sunY, 30,30 ); fill( 255,0,0 ); // red house rect( 200,horizon-80, 100,80 ); fill(0); rect( 220,horizon-60, 30,60 ); // door } //// Write your own functions, //// to organize the draw() code: /* Draw the scene sky grass house Show the objects: Draw the sun Draw the dog Action! Move the sun Move the dog Messages Title Author (Hide the details, to get the big picture.) */ //// Action: Make Dog follow the mouse. void action() { sunX = sunX + 1; // Sun moves across sky dogX= mouseX; dogY= mouseY; } //// Show: draw dog void show() { fill( 127, 0, 0 ); // brown dog rect( dogX,dogY, 80,40 ); // body rect( dogX+60,dogY-15, 30,20 ); // head } //// Messages: title & author void messages() { text( title, width/3, 30 ); text( author, 20, height-20 ); }