//////// X1 //////// Yixing Tao (CST 112; 9/18/2015) //// GLOBALS: coordinates, speed, etc. float x, y; // Position of creature. float dx, dy; // Speed. float horizon; //// SETUP: window size, initialization (start in middle of screen). void setup() { size( 640,480); horizon= height/4; x= width/2; y= height/2; dx= 3; dy= 2; } //// NEXT FRAME: scene, action, show. void draw() { //// SCENE: sky, sun, tree, house, etc. background( 100,150,200 ); // sky fill( 255,255,0 ); ellipse( width*3/4, height/8, 40,40 ); // sun // Grass fill( 100,200,100 ); rect( 0,horizon, width,height*3/4 ); // grass. fill(150); triangle(450, 245, 245, 150, 150, 70); fill(255,100,100); rect(450, 350, 150, 105); //house triangle( 150,horizon, 120,horizon-50, 180,horizon-50 ); // tree text( "This is NOT a good tree; please fix it!", 150,horizon ); // house fill(0); text( "My name is Mud", 10,height-20 ); //// ACTION: move (x,y) coordinates. x= x + dx; y= y + dy; //// SHOW: display the creature at (x,y) /* INSERT YOUR CODE HERE! */ fill(255,0,0); rect( x,y, 30,50 ); /* REPLACE THIS WITH YOUR OWN CODE! */ text( "Fred", x,y ); } //////// HANDLERS: mouse clicks, keys void mousePressed() { x= mouseX; // Set (x,y) to mouse y= mouseY; // dx= random( -6, +6 ); // random speed. dy= random( -4, +4 ); } void keyPressed() { if (key == 'q') { exit(); // press 'q' key to QUIT. } }