// Project #1 & 2 // // Stacy Aparicio, CST 112, May 8 2015 // float kayX, kayY; float booX, booY; float horizon, sunX, sunY; float treeX = 5; float treeY = horizon -40; float space = 75; float houseX, houseY; void setup() { // Setup: window size // size( 650, 650 ); horizon= ( height /3 ); } void draw() { scene(); sun(); tree(); house(); boo(); kay(); keyPressed(); } void scene() { // light blue sky // background( 0, 180, 255 ); // green grass // fill( 0, 155, 0 ); rectMode(CORNER); rect( 0, horizon + 0, width, height *4 ); // title, name, etc // fill( 0 ); textSize( 20 ); text( "boo follows kay", width/3, 20 ); textSize( 12 ); text( "Stacy Aparicio, CST 112, 2015 May 8", 20, height -20 ); } void sun() { // sun moves slowly to the right // sunX= sunX +1.5 ; sunX= sunX % width ; sunY= horizon - 155 * sin( PI * sunX/width ); // rise & set // fill( 255, 200, 0 ); ellipse( sunX, sunY, 80, 80 ); fill( 0 ); } void tree () { // Draw trees going across // treeX = -20; while ( treeX < width ) { fill( 150, 55, 0 ); // brown tree trunk // rectMode( CENTER ); rect( treeX, horizon -45 , 20 , 90 ); fill( 0, 155, 0 ); // Leaves are green // ellipse( treeX, treeY +145 , 60 , 60 ); treeX += 65 ; } } void house() { // House // float houseX, houseY ; houseX = width *9/11 ; houseY = horizon -60; fill( 0, 0, 255 ); noStroke(); rectMode( CORNER ); rect( houseX, houseY, 100, 60 ); triangle( houseX, houseY, houseX +100, houseY, houseX +50, houseY -25 ); stroke( 0 ); // Windows & door // fill( 0 ); rect( houseX +5 , horizon -50 , 25 , 20 ); rect( houseX +65 , horizon -50 , 25 , 20 ); rect( houseX +40 , horizon -30 , 20 , 30 ); } void boo() { // boo followed by kay // color navy // HERO // booX = booX + (kayX - booX)/100; booY = booY + (kayY - booY)/100; rectMode(CORNER); // Monster head // fill( 255 , 255 , 255 ); ellipse( kayX +15 , kayY , 45 , 50 ); // Monster body // fill( 0 , 23 , 145 ); rect( kayX, kayY +20 , 30 , 60 ); } void kay() { // kay follows boo // color purple // // MONSTER // kayX = kayX + (mouseX - booX)/80; kayY = kayY + (mouseY - booY)/80; rectMode(CORNER); // Creature head // fill( 0 , 0 , 0 ); rect( booX +0 , booY -5 , 30 , 50 ); // Creature body // fill( 200 , 0 , 200 ); rect( booX , booY +20 , 30 , 60 ); } void keyPressed() { if (key == 'q') exit(); }