// Project # 1 & 2 & 3 // // 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; int step; float bird1X, bird1Y=20; float bird2X, bird2Y=40; float bird3X, bird3Y=10; float bird4X, bird4Y=15; void setup() { // Setup: window size // size( 650, 650 ); horizon= ( height /3 ); } void draw() { scene(); sun(); tree(); house(); boo(); kay(); birds(); 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 +2 ; sunX= sunX % width ; sunY= horizon -200 * 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 , 25 , 90 ); fill( 0, 155, 0 ); // Leaves are green // ellipse( treeX, treeY +145 , 63 , 85 ); treeX += 65 ; } } void house() { // House // float houseX, houseY ; houseX = width *9.2/11 ; houseY = horizon -60; fill( 0, 0, 255 ); noStroke(); rectMode( CORNER ); rect( houseX, houseY, 100, 60 ); triangle( houseX, houseY, houseX +100, houseY, houseX +52, houseY -25 ); stroke( 0 ); // Windows & door // fill( 0 ); rect( houseX +5 , horizon -50 , 25 , 20 ); rect( houseX +65 , horizon -50 , 25 , 20 ); rect( houseX +38 , 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 birds() { /* . */ // Draw & move // bird1X += random(3,5); bird2X += random(2,4); bird3X += random(1,3); bird4X += random(4,6); fill( 245 , 245 , 220 ); // beige // drawBird( bird1X, bird1Y+5-random(5) ); fill( 255 , 105 , 180 ); // hot pink // drawBird( bird2X, bird2Y ); fill( 100 ); // light blue // drawBird( bird3X, bird3Y ); fill( 0,255,255 ); // grey // drawBird( bird4X, bird4Y ); } void drawBird( float x, float y ) { /* . */ // draw one bird // triangle( x,y, x-60,y-10, x-60,y+10 ); // Make the wings flap // float flap; if ( step/30 % 4 == 0 ) flap= 20; else if ( step/30 % 4 == 1 ) flap= -10; else if ( step/30 % 4 == 2 ) flap= -20; else flap= +10; birdWing( x, y, flap ); } void birdWing( float x, float y, float yup ) { /* . */ // Draw the wing // triangle( x-20,y, x-40,y, x-40,y-yup ); } void keyPressed() { if (key == 'q') exit(); }