Modify a text file: $/p1.pde
$/p1.pde
//Project 1; Benjamin Canfora float xCat, yCat, cxSpeed, cySpeed; float lSize; color hColor; float xSun = -25; float ySun = 100; float xMoon = -25; float yMoon = 100; boolean day=true; void setup() { size(600, 600); lSize = 50; hColor = #AA2429; xSun=0; ySun=100; xCat = 300; yCat = 300; cxSpeed = 2; cySpeed = 2; } void draw() { if (day) { sun(); } else { moon(); } //Instructions fill(255, 255, 255); textSize(20); text("p1: Animated House", width/3.5, 20); text("Author: Ben Canfora", width/3.5, 40); textSize(15); text("Press 'C' to change", 10, 20); text("the house color.", 10, 40); text("Press 'L' to change", 10, 65); text("the leaves' size.", 10, 85); text("Click to move the cat", 10, 110); text("to another part of the grass.", 10, 130); //Grass fill(#35BC0D); rect(0, 195, 600, 600); //Tree Trunks fill(#713302); rect(60, 350, 20, 50); rect(170, 515, 22, 60); rect(380, 412, 20, 55); //Tree leaves fill(#226C03); ellipse(70, 335, lSize, lSize); ellipse(181, 500, lSize, lSize); ellipse(390, 397, lSize, lSize); //Small House fill(hColor); rect(230, 150, 80, 80); triangle(230, 150, 310, 150, 270, 90); //Door fill(#713B08); rect(263, 205, 12, 24); //Cat //Horizontal Movement xCat += cxSpeed; //Vertical Movement yCat += cySpeed; //Makes the cat Bounce of the edges of the screen and grass if (xCat >= width - 37 || xCat <= 0 + 37) { cxSpeed *= -1; } if (yCat >= height - 20 || yCat <= 217) { cySpeed *= -1; } fill(#000000); //Body rect(xCat, yCat, 30, 18); //Head rect(xCat-10, yCat-15, 20, 20); //Tail line(xCat +30, yCat, xCat+40, yCat+2); //Ear triangle(xCat-2, yCat-15, xCat+8, yCat-15, xCat+2, yCat-21); fill(#FFB7FA); triangle(xCat, yCat-15, xCat+6, yCat-15, xCat+2, yCat-19); //Changes leaf size or house color based on pressed key if (keyPressed) { if (key == 'c' || key == 'C') { int c1, c2, c3; c1 = int(random(0, 256)); c2 = int(random(0, 256)); c3 = int(random(0, 256)); hColor = color (c1, c2, c3); } if (key == 'l' || key == 'L') { lSize = random(50, 85); } } } //Moves the Cat to the mouse's position as long as it is on the grass. void mousePressed() { if (mouseY >217) { xCat = mouseX; yCat = mouseY; } } void sun() { //display sun background(100, 100, 250); stroke(0); fill(255, 250, 0); float up= 50 * sin(PI * xSun/width ); ellipse(xSun, ySun-up, 50, 50); //movement sun xSun+=3; if (xSun > 625) { day = false; xSun=-25; // Get ready for next day. } } void moon() { //display moon background(10, 10, 80); stroke(50); fill(150); float up= 50 * sin(PI * xMoon/width ); ellipse(xMoon, yMoon-up, 40, 40); //movement Moon xMoon+=3; if (xMoon > 625) { day = true; xMoon=-25; } }