Project – 2020 Calendar

2020 Calendar shaunmurDownload
//Diana McLaughlin and Shaun Murray
//dmclaugh@andrew.cmu.edu and shaunmur@andrew.cmu.edu
//Section A and Section B
//A calendar commemorating a major event from each month in 2020
//All global variables except image variables are with the start of the respective month's program. Some of these variables are called in set up, but you'll find them before their clickMonthX() function
//Shaun's code starts at clickMonthJan(). He also wrote the makeCalendar(), clearBkgd(), and backButton() functions
//Diana's code starts at clickMonthJul(). She also wrote the writeMonths() function
//Aside from the makeCalendar and writeMonths functions, Shaun did everything related to January - June and Diana did everything related to July - December
//"The biggest waste of computer processing power in 15-104" -Shaun

//Image Variables
//for the main calendar
var imgJanCal, imgFebCal, imgMarCal, imgAprCal, 
	imgMayCal, imgJunCal, imgJulCal, imgAugCal, 
	imgSepCal, imgOctCal, imgNovCal, imgDecCal;

//for the month functions
var imgJan2, imgMar, aprImg, aprImg2, 
    aprImg3, imgJun1, imgJun2, imgJun3, 
    imgJul, imgOct, imgNov;


function preload() {
	imgJanCal = loadImage("https://i.imgur.com/mGCWr67.jpg?2"); //January main calendar
	imgFebCal = loadImage("https://i.imgur.com/8hI9x3x.jpg"); //February main calendar
	imgMarCal = loadImage("https://i.imgur.com/hozlVRU.jpg"); //March main calendar
	imgAprCal = loadImage("https://i.imgur.com/PUDQpPe.jpg"); //April main calendar
	imgMayCal = loadImage("https://i.imgur.com/FyUdmy7.png"); //May main calendar
	imgJunCal = loadImage("https://i.imgur.com/1V9Akde.jpg"); //June main calendar
	imgJulCal = loadImage("https://i.imgur.com/Tvukiin.jpg"); //July main calendar
	imgAugCal = loadImage("https://i.imgur.com/kECFW1b.jpg"); //August main calendar
	imgSepCal = loadImage("https://i.imgur.com/O6e3LcQ.jpg"); //September main calendar
	imgOctCal = loadImage("https://i.imgur.com/CcQpShS.jpg"); //October main calendar
	imgNovCal = loadImage("https://i.imgur.com/8Sqt5Um.jpg"); //November main calendar
	imgDecCal = loadImage("https://i.imgur.com/DrModlG.jpg"); //December main calendar

    imgJan = loadImage("https://i.imgur.com/UO8RoiW.png"); //santa hat for JAN
    imgJan2 = loadImage("https://i.imgur.com/lM5i1Gp.jpeg") //A-Bomb Jan
    imgFeb = loadImage("https://i.imgur.com/AIq3z8n.jpeg"); //House Chamber background
    imgMar = loadImage("https://i.imgur.com/VFoP91O.png"); //background image for March
    mayImg1 = loadImage("https://i.imgur.com/RhNvf13.jpeg"); //Kim Jong Un
	mayImg2 = loadImage("https://i.imgur.com/huOal0b.png"); //podium
	mayImg3 = loadImage("https://i.imgur.com/20G2Bj4.jpg"); //NK flag
    aprImg = loadImage("https://i.imgur.com/G0SnXSB.jpg"); //Tiger
	aprImg2 = loadImage("https://i.imgur.com/VVfSCll.jpeg"); //Oklahoma
	aprImg3 = loadImage("https://i.imgur.com/IgLfZQb.png"); //Joe Exotic
	imgJun1 = loadImage("https://i.imgur.com/V8MHehF.jpg"); //St John's Church
	imgJun2 = loadImage("https://i.imgur.com/on3fzqb.jpg"); //President
	imgJun3 = loadImage("https://i.imgur.com/SAUkUd3.jpg"); //Protesters
	imgJul = loadImage("https://i.imgur.com/FXdV1Bk.jpg"); //John Lewis photograph for July
    imgOct = loadImage("https://i.imgur.com/a7W8anl.png"); //map for Oct
    imgNov = loadImage("https://i.imgur.com/OCT1IpR.jpg"); //auditorium for November
}

function setup() {
    createCanvas(500, 400);
    makeCalendar();

    //set up March
    for (var i = 0; i < 1; i++) {
    // make virus cell
    	var v = makeVirus(200, 200,
                             random(-50, 50), random(10, 50));
        viruses.push(v);
    }

    //set up for April
    for (var i = 0; i < 12; i++){ // create an initial collection of cats
        var rx = random(width);
        tigers[i] = makeTigers(rx);
    }

    //set up August
    for (var i = 0; i < 1; i++){
        var hy = random(height/3, height);
        hurricane[i] = makeHurricane(hy);
    } 
    
    //set up September
    //set up mountains
    for (var i = 0; i <= 100; i++) {
        var n = noise(noiseParam);
        var value = map(n, 0, 1, 0, height/2);
        mountain.push(value);
        noiseParam += noiseStep;
    }  

    //set up fire
    for (var i = 0; i <= 100; i++) {
        var n = noise(fNoiseParam);
        var value = map(n, 0, 1, 0, height);
        fire.push(value);
        fNoiseParam += fNoiseStep;
    }  
    
    //draw initial trees
    for (var i = 0; i < 10; i++){
        var rx = random(width);
        trees[i] = makeTree(rx);
    }
    
    //draw initial smoke clouds
    for (var i = 0; i < 10; i++){
        var cx = random(width);
        smoke[i] = makeSmoke(cx);
    }
    
}

function draw() {
	clickMonthJan();
	clickMonthFeb();
	clickMonthMar();
	clickMonthApr();
	clickMonthMay();
	clickMonthJun();
	clickMonthJul();
	clickMonthAug();
	clickMonthSep();
	clickMonthOct();
	clickMonthNov();
	clickMonthDec();
	backButton();
}

function makeCalendar() {
	fill(0);
    strokeWeight(1);
    //draw lines between the months on the calendar
    for (let i = 0; i < 3; i++) {
        line(0, i*133.33 + 133, width, i*133.33 + 133);
        line(i*125 + 125, 0, i*125 + 125, height);
    }

    //background pictures
    var calPics = [imgJanCal, imgFebCal, imgMarCal, imgAprCal, imgMayCal, imgJunCal, imgJulCal, imgAugCal, imgSepCal, imgOctCal, imgNovCal, imgDecCal];
    var xCo = [0.5, 125.5, 250.5, 375.5, 0, 125.5, 250.5, 375.5, 0.5, 125.5, 250.5, 375.5];
    var yCo = [0, 0, 0, 0, 132.83, 132.83, 132.83, 132.83, 267.16, 267.16, 267.16, 267.16];
    for (var i = 0; i < calPics.length; i++) {
    	image(calPics[i], xCo[i], yCo[i], 124.5, 132.83);
    }

    writeMonths();

}

function writeMonths() {
	//display text on calendar
	var monthText = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
	var monthCode = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "0", " ", "="];
	var monthX = [55, 180, 305, 430, 55, 180, 305, 430, 55, 180, 305, 430];
	var monthY = [65, 65, 65, 65, 200, 200, 200, 200, 335, 335, 335, 335];
	strokeWeight(1);
	textFont('Times');
    textSize(24);
    textAlign(CENTER);
    stroke(0);
    fill(255);
    for (var i = 0; i < monthText.length; i++) {
    	text(monthText[i], monthX[i], monthY[i]);
    	text(monthCode[i], monthX[i], monthY[i] + 30);
    }
    textSize(40);
    text("-", 300, 363);
    textSize(15);
    textAlign(LEFT);
    text("Press a key to begin", 3, 25); //written instruction
    text("Press ESC to return", 380, 25);
}

function backButton() { //click to return to calendar
    if (keyCode === 27) {
        clearBkrd();
        makeCalendar();

        //reset March
        v.diam = 25;

        //reset November
        pCount = 0;
        vpCount = 0;
    }
}

function clearBkrd() { //clear background
    background(255);
}

//Shaun's Code

function clickMonthJan() {
	//Referencing the anticipation of North Korea's overdue X-mas gift
    if (keyCode === 49) {
        clearBkrd();
        frameRate(30);
        JanBackground();
        USflag();
        NKflag();
        nuclear(width/2, height/2);
        JanText(45, height-85);
        backButton(); 
    }
         
}

	function JanBackground() {
		image(imgJan2, 0, 0, width, height);
	}

    function starJan() {
        var x1 = [340, 348, 364, 354, 356, 340, 324, 326, 315, 332]; //star points
        var y1 = [44, 58, 62, 75, 92, 85, 92, 75, 62, 58];
        var nPoints= x1.length;
        beginShape();
        fill('Red');
        for (var i= 0; i< nPoints; i++) {
            vertex(x1[i] + 35, y1[i] + 5);
        }
        endShape(CLOSE);
    }

    function USflag() {// United States Flag minus stars
        fill('Red');
        rect(25, 25, width/3, height/4);
        for(let i = 0; i < 7; i++) { //white rects on flag
            fill('white');
            rect(25, 30 + (i * 13.5), width/3, 7);
        }
        fill(0, 0, 155);
        rect(25, 25, 50, 50);
    }

    function NKflag() { //North Korean Flag
        fill('Blue');
        rect(width-164, 25, width/3, height/4);
        push();
        fill('Red');
        strokeWeight(5);
        noStroke();
        rect(width-163, 40, width/3 + 6, 70); //white border in flag
        stroke('White');
        line(width, 40, width-161, 40);
        line(width, 110, width-161, 110);
        pop();
        noStroke();
        fill('White');
        circle(width-125, 75, 53);
        stroke(0);
        push();
        starJan();
        pop();
    }

    function nuclear(x, y) { //nuclear symbol
        push();
        translate(x, y);
        let d = 80
        let d1 = 10
        stroke(0);
        strokeWeight(3);
        fill('yellow'); //draw circles
        circle(0, 0, d);
        fill('black');
        circle(0, 0, d1);

        let deg = 120;
        let dx = 5;
        let angle = 45;

        rotate(radians(angle));
        for (let i = 0; i < 3; i++) { //draw triangles 
            rotate(radians(deg));
            beginShape();
            fill('black');
            vertex(-7, -7);
            vertex(-30, -10);
            vertex(-10, -30);
            endShape(CLOSE);
        }

        angle = angle + dx;
        pop();

        push();
        rotate(radians(-20));
        image(imgJan, 135, 185, 100, 100); //santa hat
        pop();

    }

    function JanText(x, y) { //display text for Jan
        push();
        translate(x, y);
        textSize(23);
        fill(255);
        text("United Shaysh of America VS. North Korea", 0, 0);
        pop();
    }

//Global variables for Feb
var rip = 0//checks to see if SotU is ripped

function clickMonthFeb() {
	//Referencing the ripped speech at the State of the Union address
    if (keyCode === 50) {
        clearBkrd();
        frameRate(30);
        drawPaper();
		drawRip();
		mendPaper();
        backButton();
    }   
    
}

	//February helper functions
	function drawPaper() { //draw initial SotU
		push();
		background('grey');
		image(imgFeb, 0, 0);
		fill('white');
		rectMode(CENTER);
		rect(width/2+30, height/2, 200, 300);
		rect(width/2+15, height/2, 200, 300);
		rect(width/2, height/2, 200, 300);
		textStyle(ITALIC);
		textSize(22);
		fill('black');
		text("State of the Union", 160, 80);
		fill('white');
		text("Click and hold to rip!", width-205, 25);
		text("Nancy Pelosi Simulator", 10, 25);
		line(180, 110, 320, 110);
		for (let i = 0; i < 20; i++) {
			line(165, 120 + i*11, 335, 120 + i*11);
		}
		pop();
	}

	function drawRip() { //Rip SotU
		push();
		if (mouseIsPressed) {
			background('grey');
			image(imgFeb, 0, 0);
			textStyle(ITALIC);
		    textSize(22);
			fill('white');
			text("Release mouse to mend...", 10, 25);
			push();
			rotate(radians(-30));
			fill('white');
			rectMode(CORNER);
			rect(width/2-300, height/2-80, 100, 300);
			for (let i = 0; i < 20; i++) {
				line(-40, 190 + i*11, 40, 190 + i*11);
			}
			fill('black');
			text("State of t", -50, 160);
			rotate(radians(60));
			fill('white');
			rect(width/2+160, height/2-345, 100, 300);
			for (let j = 0; j < 20; j++) {
				line(width/2+175, height/2-280 + j*11, width/2+250, height/2-280 + j*11);
			}
			fill('black');
			text("he Union", width/2+162, height/2-300);
			pop();
			pop();
			rip = 1;
		}
	}

	function mendPaper() { //Tape SotU back together like a good American
		push();
		if (rip == 1 & !mouseIsPressed) {
			background('grey');
			image(imgFeb, 0, 0);
			fill('white');
			rectMode(CENTER);
			rect(width/2+30, height/2, 200, 300);
			rect(width/2+15, height/2, 200, 300);
			rect(width/2, height/2, 200, 300);
			textStyle(ITALIC);
			textSize(22);
			fill('black');
			text("State of the Union", 160, 80);
			fill('white');
			text("Click and hold to rip!", width-205, 25);
		    text("Nancy Pelosi Simulator", 10, 25);
			fill('black');
			line(180, 110, 320, 110);
			for (let i = 0; i < 20; i++) {
				line(165, 120 + i*11, 335, 120 + i*11);
			}
	        fill(255, 248, 220);
			rect(width/2-15, height/2, 30, 300);
			pop();
		}
	}
//Global variable for March
var viruses = [];

function clickMonthMar() {
	//Referencing the spread of COVID-19 in the U.S.
    if (keyCode === 51) {
        clearBkrd();
        backButton();
        frameRate(15);
        image(imgMar, 0, 0, 500, 400);

	    for (var i = 0; i < viruses.length; i++) {
	        var v = viruses[i];
	        v.stepFunction();
	        v.drawFunction();
	        if (v.diam > 450) {
	        	background(0);
	        	stroke(255, 0, 0);
	        	strokeWeight(4);
	        	push();
	        	textSize(48);
	        	translate(width/2, height/2)
	        	rotate(radians(90));
	        	text(":(", 0, 0);
	        	pop();
	        	stroke(0);
	        	strokeWeight(2);
	        	fill('white');
	        	text("Sad", width/2, height/2 + 100);
	        }
	    }
    }   
    
}

	//March Helper Functions
	function virusStep() {
    this.age++;
    this.x += this.dx;
    this.y += this.dy;
    if (this.x > width) { // bounce off right wall
        this.x = width - (this.x - width);
        this.dx = -this.dx;
        this.diam *= 1.25;
    } else if (this.x < 0) { // bounce off left wall
        this.x = -this.x;
        this.dx = -this.dx;
        this.diam *= 1.25;
    }
    if (this.y > height) { // bounce off bottom
        this.y = height - (this.y - height);
        this.dy = -this.dy;
        this.diam *= 1.25;
    } else if (this.y < 0) { // bounce off top
        this.y = -this.y;
        this.dy = -this.dy;
        this.diam *= 1.5;
    }
	}


	function virusDraw() {
		stroke('black');//body of virus
		strokeWeight(2);
		fill('red');
		push();
	    translate(this.x, this.y);
		circle(0, 0, this.diam);
		strokeWeight(3);//stems of virus
		var angle = 45;
		for (let i = 0; i < 8; i++) {
			rotate(radians(angle));
			beginShape();
	        vertex(this.diam/2 - 10, 0)
	        vertex(random(this.diam/2 + 4, this.diam/2 + 8), random(-2, 2));
	        endShape(CLOSE);
	        ellipse(random(this.diam/2 + 8, this.diam/2 + 6), random(1, 3), 11, 9);
	    }
	    pop();
	}


	// create a "Particle" object with position and velocity
	function makeVirus(vx, vy, vdx, vdy) {
	    v = {x: vx, y: vy,
	         dx: vdx, dy: vdy,
	         age: 0,
	         diam: 25,
	         stepFunction: virusStep,
	         drawFunction: virusDraw
	        }
	    return v;
	}	

// Global variables for April
var tigers = [];
var deg = 10
var joe = 1;

function clickMonthApr() {
	//Referencing the popularity of the Tiger King documentary on NETFLIX in March/April
    if (keyCode === 52) {
        clearBkrd();
        frameRate(12);
        displayHorizon();
   		updateAndDisplayTigers();
    	removeTigersThatHaveSlippedOutOfView();
    	addNewTigersWithSomeRandomProbability();
        backButton();
    }
       
}

	function updateAndDisplayTigers(){
	    // Update the cats' positions, and display them.
	    for (var i = 0; i < tigers.length; i++){
	        tigers[i].move();
	        tigers[i].display();
	    }
	}


	function removeTigersThatHaveSlippedOutOfView(){
	    var tigersToKeep = [];
	    for (var i = 0; i < tigers.length; i++){
	        if (tigers[i].x + tigers[i].breadth > 0) {
	            tigersToKeep.push(tigers[i]);
	        }
	    }
	    tigers = tigersToKeep; // remember the surviving tigers
	}


	function addNewTigersWithSomeRandomProbability() {
	    // With a very tiny probability, add a new cat to the end.
	    var newTigersLikelihood = 0.03; 
	    if (random(0,1) < newTigersLikelihood) {
	        tigers.push(makeTigers(width));
	    }
	}


	// method to update position of cat every frame
	function tigersMove() {
	    this.x += this.speed;
	}
	    

	// draw the cat and more cats
	function tigersDisplay() {
	    push();
	    translate(this.x, height - floor(random(30, 40))); 
	    image(aprImg, 0, -15, 80, 35);
	    pop();
	}


	function makeTigers(birthLocationX) {
	    var tgs = {x: birthLocationX,
	                breadth: 50,
	                speed: -1.0,
	                move: tigersMove,
	                display: tigersDisplay}
	    return tgs;
	}

	function displayHorizon(){
		image(aprImg2, 0, 0, width, height);
		push();
		translate(60, 80);
		imageMode(CENTER);
		rotate(radians(deg));
		for (let i = 0; i < joe; i++) {
			image(aprImg3, 0, 0, 80, 80);
		}
		pop();
		deg = deg + 10;
	}

function clickMonthMay() {
	//Referencing Kim Jong Un's questionable health and reappearance
    if (keyCode === 53) {
        clearBkrd();
        frameRate(60);
        drawBackdrop();
		leader();
		drawPodium();
        backButton(); 
    }  
    
}

	//May helper functions
	function leader() {//place Kim on canvas
		push();
		var top = height/2;
	    var bottom = height;
	    var conY = constrain(mouseY, top, bottom);
		imageMode(CENTER);
		image(mayImg1, width/2, conY, 120, 180);
		pop();
	}

	function drawPodium() {//place podium
		push();
		imageMode(CENTER);
		image(mayImg2, 250, 400, 300, 250);
		pop();
	}

	function drawBackdrop() {//draw flag background
		push();
		imageMode(CENTER);
		image(mayImg3, width/2, height/2, 500, 400);
		textSize(20);
		fill('black');
		text("N.K. Leader Simulator", 10, 30);
		text("Moves with your mouse!", width-210, 30);
		pop();
	}

//Global variable June
var moveJun = 1;

function clickMonthJun() {
	//Referencing President Trump's removal of protesters from St. John's church in D.C.
    if (keyCode === 54) {
        clearBkrd();
        frameRate(30);
        drawChurch();
	    drawPres();
	    drawProtest();
	    fightBack();
        backButton();  
    } 
}

	function drawChurch() {//draw church background
		push();
		imageMode(CENTER);
		image(imgJun1, width/2, height/2, 500, 400);
		textSize(20);
		fill('black');
		text("Click and hold mouse to fight back!", 10, 25);
		pop();
	}

	function drawPres() {//place President on canvas
		push();
		var junX1 = width - 50;
		var conX1 = constrain(junX1 - moveJun, 230, width + 60);
		imageMode(CENTER);
		image(imgJun2, conX1 , height-50, 120, 130);
		pop();
	}

	function drawProtest() {//place protesters on canvas
		push();
		var junX2 = 80;
		var conX2 = constrain(junX2 - moveJun, -100, 230);
		imageMode(CENTER);
		image(imgJun3, conX2, height-50, 200, 150);
		pop();
	}

	function fightBack() {//adjusts Xpos of pres and protest on canvas, default move left
		push();
		moveJun ++;
		print(moveJun);

		if (mouseIsPressed) {
			moveJun -= 2;
		}

		moveJun = constrain(moveJun, -150, 230);
		pop();
	}

//Diana's Code

var julXPoints = [];
var julYPoints = [];
var julClr = [];

function clickMonthJul() {
//Remembering John Lewis
    if (keyCode === 55) {
    	clearBkrd();
    	frameRate(60);
        imgJul.resize(width, height);
        imgJul.loadPixels();
        var x = random(width); //randomly draw pixels for a portrait of John Lewis
	    var y = random(height);
	    var clr = imgJul.get(x, y);
    	stroke(clr);
		strokeWeight(5);
	   	noFill();
	   	point(x, y); 
	   	julXPoints.push(x); //push the coordinates into arrays so it doesn't look like the background keeps drawing over it
	   	julYPoints.push(y);
	   	julClr.push(clr);
	   	for (var i = 0; i < julXPoints.length; i++) {
	   		stroke(julClr[i]);
	   		point(julXPoints[i], julYPoints[i]);
	   	}
        backButton(); 
    }
      
}

function clickMonthAug() {
//SpaceX Launch
	strokeWeight(1);
	stroke(0);
    if (keyCode === 56) {
        clearBkrd();
        background(0);
        frameRate(30);
		for (var i = 0; i < 3; i++) {
			for(var j = 0; j < 4; j++){
				star(i*200 + 25, j*100);
			}	
		}

		for (var a = 0; a < 2; a++) {
			for (var b = 0; b < 4; b++) {
				star(a*200 + 125, b*100 + 50);
			}
		}
		spaceship(200, 150);
		backButton(); 
	    }
}
    //August Helper Functions
	function spaceship(x, y) {
		push();
		translate(x, y);
		rotate(radians(30));
		fill(255);
		ellipse(25, 0, 50, 100); //spaceship body
		rect(0, 0, 50, 150);
		stroke(255, 0, 0);
		strokeWeight(3);
		push();
		rotate(radians(-90));
		text("SpaceX", -120, 25);
		pop();
		stroke(0);
		strokeWeight(1);
		triangle(0, 75, 0, 150, -35, 150); //wings
		triangle(50, 75, 50, 150, 85, 150);
		push();
		translate(-35, 150);
		for (var i = 0; i < 3; i++) { //draw flames
			fill(255, 175, 0);
			triangle(i*40, 0, (i+1)*40, 0, (i*40 + random(15, 25)), random(95, 105));
		}
		pop();
		pop();
	}

	function star(x, y) {
		var sx = [0, 5.5, 16.5, 9.5, 10.5, 0, -10.5, -9.5, -16.5, -5.5];
		var sy = [0, 9.5, 12.5, 21, 32, 27.5, 32, 21, 12.5, 10.5];
		push();
		translate(x, y);
		fill(255, 255, 0);
	    var nPoints = sx.length;
	    beginShape();
	    for (var i = 0; i < nPoints; i++) {
	    	vertex(sx[i] + random(-1, 1), sy[i] + random(-1, 1));
	    }
	    endShape(CLOSE);
	    pop();
	}

//Global Variables for September
var trees = [];
var smoke = [];
var mountain = [];
var fire = [];
var noiseParam = 0; //controls mountain landscape
var noiseStep = 0.01;
var fNoiseParam = 0; //controls fire
var fNoiseStep = 0.05;

function clickMonthSep() {
//West Coast Wildfires
    if (keyCode === 57) {
        clearBkrd();
        text("Sep TEST", width/2, height/2);
        backButton();
        frameRate(10);
        background(100); //dark grey

	    updateAndDisplaySmoke();
	    removeSmokeThatHasSlippedOutOfView();
	    addNewSmokeWithSomeRandomProbability();

	    mountains();
	    makeFire();
	    fill(75);
	    rect(0, 335, width, 65); //ground

	    updateAndDisplayTrees();
	    removeTreesThatHaveSlippedOutOfView();
	    addNewTreesWithSomeRandomProbability();   
	}
}

//September Helper Functions
	function updateAndDisplayTrees(){
	    // Update the trees' positions
	    for (var i = 0; i < trees.length; i++){
	        trees[i].move();
	        trees[i].display();
	    }
	}


	function removeTreesThatHaveSlippedOutOfView(){
	    //remove these trees from the array
	    var treesToKeep = [];
	    for (var i = 0; i < trees.length; i++){
	        if (trees[i].x + trees[i].breadth > 0) {
	            treesToKeep.push(trees[i]);
	        }
	    }
	    trees = treesToKeep;
	}


	function addNewTreesWithSomeRandomProbability() {
	    // Add a new tree to the end of the array
	    var newTreeLikelihood = 0.05; 
	    if (random(0,1) < newTreeLikelihood) {
	        trees.push(makeTree(width));
	    }
	}

	function treeMove() {
	    this.x += this.speed;
	}
	    
	function treeDisplay() {
	    //draw the tree
	    var tHeight = 90; 
	    strokeWeight(5);
	    stroke(0); 
	    push();
	    translate(this.x, height - 40);
	    line(0, -tHeight, 0, 0);
	    line(0, -40, -22, -75);
	    line(0, -40, 22, -75);
	    line(0, -50, -15, -85);
	    line(0, -50, 15, -85);
	    line(0, -30, -30, -65);
	    line(0, -30, 30, -65);
	    stroke(200); 
	    pop();
	}


	function makeTree(birthLocationX) {
	    var tr = {x: birthLocationX,
	                breadth: 50,
	                speed: -3.5,
	                move: treeMove,
	                display: treeDisplay}
	    return tr;
	}

	//Smoke Clouds

	function updateAndDisplaySmoke(){
	    // Update the smoke positions
	    for (var i = 0; i < smoke.length; i++){
	        smoke[i].move();
	        smoke[i].display();
	    }
	}


	function removeSmokeThatHasSlippedOutOfView(){
	    // remove clouds that are no longer visible
	    var smokeToKeep = [];
	    for (var i = 0; i < smoke.length; i++){
	        if (smoke[i].x + smoke[i].breadth > 0) {
	            smokeToKeep.push(smoke[i]);
	        }
	    }
	    smoke = smokeToKeep;
	}


	function addNewSmokeWithSomeRandomProbability() {
	    // Add smoke clouds to the end of the arrayS
	    var newSmokeLikelihood = 0.02; 
	    if (random(0,1) < newSmokeLikelihood) {
	        smoke.push(makeSmoke(width));
	    }
	}

	function smokeMove() {
	    this.x += this.speed;
	}
	    

	// draw smoke
	function smokeDisplay() { 
	    fill(50); 
	    noStroke(); 
	    push();
	    translate(this.x, this.y);
	    ellipse(0, this.y, 90, 15);
	    ellipse(0, this.y+10, 100, 15);
	    ellipse(0, this.y-10, 80, 15);
	    pop();
	}


	function makeSmoke(birthLocationX) {
	    var smk = {x: birthLocationX,
	    	        y: random(0, height/2),
	                breadth: 50,
	                speed: -3.,
	                move: smokeMove,
	                display: smokeDisplay}
	    return smk;
	}


	function mountains() {
	    //use random noise to draw mountains
	    mountain.shift();
	    var n = noise(noiseParam);
	    var value = map(n, 0, 1, 0, height);
	    mountain.push(value);
	    noiseParam += noiseStep;
	    
	    
	    fill(0); //black - mountain shadows
	    beginShape();
	    vertex(0, height);
	    for (var i = 0; i <= 100; i++) {
	        vertex(i*5, mountain[i]);
	    }
	    vertex(width, height);
	    endShape(); 
	}

	function makeFire() {
	    //use random noise to draw mountains
	    fire.shift();
	    var n = noise(fNoiseParam);
	    var value = map(n, 0, 1, 0, height);
	    fire.push(value);
	    fNoiseParam += fNoiseStep;
	    
	    
	    fill(255, 0, 0); //red layer
	    beginShape();
	    vertex(0, height);
	    for (var i = 0; i <= 100; i++) {
	        vertex(i*5, fire[i]);
	    }
	    vertex(width, height);
	    endShape(); 

	    fill(255, 175, 0); //orange layer
	    beginShape();
	    vertex(0, height);
	    for (var j = 0; j <= 100; j++) {
	    	vertex(j*5, fire[j] + 50);
	    }
	    vertex(width, height);
	    endShape();

	    fill(255, 255, 0); //yellow layer
	    beginShape();
	    vertex(0, height);
	    for (var p = 0; p <= 100; p++) {
	    	vertex(p*5, fire[p] + 100);
	    }
	    vertex(width, height);
	    endShape();
     
}

//October Global Variables
var hurricane = [];
var xMove = [];
var imgOct;

function clickMonthOct() {
	//Busiest hurricane season on record
    if (keyCode === 48) {
        clearBkrd();
        frameRate(15);
        translate(width, 0);
	    image(imgOct, -width-50, -107, 650, 560);
		updateAndDisplayHurricane(); 
		removeHurricanesThatHaveSlippedOutOfView();
		addNewHurricanesWithSomeRandomProbability();
        backButton();
    }
}

	//October Helper Functions
		function updateAndDisplayHurricane(){
	    // Update the hurricanes' positions
	    for (var i = 0; i < hurricane.length; i++){
	        hurricane[i].move();
	        hurricane[i].display();
	    }
	}

	function removeHurricanesThatHaveSlippedOutOfView(){
	    //remove these hurricanes from the array
	    var hurricanesToKeep = [];
	    for (var i = 0; i < hurricane.length; i++){
	        if (hurricane[i].x > -550 || hurricane[i].y > -50) {
	            hurricanesToKeep.push(hurricane[i]);
	        }
	    }
	    hurricane = hurricanesToKeep;
	}

	function addNewHurricanesWithSomeRandomProbability() {
	    // Add a new hurricane to the end of the array
	    var newHurricaneLikelihood = 0.025;
	    var newHY = random(height/3, height);
	    this.xMove = random(10);
	    this.yMove = random(10);
	    if (random(0,1) < newHurricaneLikelihood) {
	        hurricane.push(makeHurricane(newHY));
	    }
	}

	function hurricaneMove() {
		this.x -= this.hxMove;
		this.y -= this.hyMove;
		this.spin += 10;
	}

	function hurricaneDisplay() {
		push();
		translate(this.x, this.y);
		rotate(radians(this.spin));
	    noStroke();
	    fill(255, 0, 0);
	    ellipse(0, 0, 30, 30);
	    fill(230);
	    ellipse(0, 0, 10, 10);
		push();
		scale(0.7);
		translate(-40, 5);
		stroke(255, 0, 0);
		strokeWeight(5);
		noFill();
		beginShape();
		for (var i = 2; i <= 4; i += 0.1) {
			var y1 = Math.pow(2.6, i);
	    	vertex(i*25, -y1);
		}
		endShape();
		pop();
	    
	    push();
	    scale(0.7);
	    stroke(255, 0, 0);
		strokeWeight(5);
		noFill();
	    translate(40, -5);
	    rotate(radians(180));
		beginShape();
		for (var i = 2; i <= 4; i += 0.1) {
			var y1 = Math.pow(2.6, i);
	    	vertex(i*25, -y1);
		}
		endShape();
		pop();
		pop();
	}

	function makeHurricane(birthLocationY) {
		var h = {x: 0, y: birthLocationY, hxMove: xMove, hyMove: 5, move: hurricaneMove, spin: 0, display: hurricaneDisplay}
	    return h;
	}

//November Global Variables
var theta = 0;
var txp = 0;
var typ = 0;
var thetavp = 0;
var txvp = 0;
var tyvp = 0;
//counters
var pCount = 0;
var vpCount = 0;

function clickMonthNov() {
//2020 US Presidential Election
    strokeWeight(1);
	stroke(0);
	textSize(14);

    if (keyCode === 189) {
        clearBkrd();
        frameRate(15);
        backButton();
        image(imgNov, -150, -60, 800, 650);
        stroke(255);
		president(150, 200);
		vicePresident(350, 200);
		fill(255);
		text("Who will be the first to 270?", 150, 20);
		text("Click the mouse on the left to give Alec Baldwin electoral votes", 75, 45)
		text("Click the mouse on the right to give Jim Carrey electoral votes", 75, 70);
		text(pCount, 150, 120);
		text(vpCount, 350, 120);
		debate();
	}

    	if (pCount >= 270) {
			background(255, 0,0);
			textSize(30);
			stroke(0);
			fill(0);
			text("I did it! It was RIGGED but I won!", 20, height/2 - 15);
			text("Very good for our Great Country", 25, height/2 + 15);
		}

		if (vpCount >= 270) {
			background(0, 0, 255);
			textSize(50);
			stroke(255);
			fill(255);
			text("Will you shut up man!", 5, height/2);
		}
	
}
    //November Helper Functions    
	function debate(){
		if (mouseIsPressed) {
			if (mouseX < width/2) { //move president
				theta = 15;
				txp = 150;
				typ = -100
				pCount = pCount + 5;				
			}

			if (mouseX >= width/2) { //move vice president
				thetavp = -15;
				txvp = -150;
				tyvp = 0;
				vpCount = vpCount + 5;
			}
		}
	} 

	function mouseReleased() {
		if (theta === 15) { //reset president
			theta = 0;
			txp = 0;
			typ = 0;					
		}

		if (thetavp === -15) { //reset vice president
			thetavp = 0;
			txvp = 0;
			tyvp = 0;				
		}
	}

	function president(x, y) {
		push();
		rotate(radians(theta));
		translate(x + txp, y + typ);
		noStroke();
		fill(255, 175, 0);
		push();
		rotate(radians(75)); //mouth
		ellipse(17, -12, 4, 15);
		rotate(radians(30));
		ellipse(15, -17, 4, 15);
		pop();
		fill(255, 175, 0); //head
		ellipse(0, 0, 40, 50);
		fill(255, 255, 0); //hair
		ellipse(3.5, -20, 45, 15);
		fill(255); //eyes
		ellipse(10, -2, 8, 8);
		fill(0);
		ellipse(10, -2, 4, 4);
		stroke(0);
		line(25, 17, 40, 17);
		line(25, 9, 40, 1);
		line(25, 25, 40, 33);
		noStroke();

		//suit
		fill(255); //shirt
		rect(-15, 23, 32, 50);
		fill(0, 0, 255); //suit jacket
		rect(-15, 23, 25, 50);
		fill(255, 0, 0); //tie
		rect(14, 23, 3, 30);
		fill(0); //shoes
		ellipse(3, 133, 35, 15);
		fill(0, 0, 255); //pants
		rect(-15, 73, 27, 60);
		push(); //arm
		rotate(radians(-40));
		fill(255, 175, 0);
		ellipse(15, 40, 15, 10);
		fill(0, 0, 255);
		rect(-35, 35, 50, 10);
		pop();
		pop();
	}

	function vicePresident(x, y) {
		push();
		rotate(radians(thetavp));
		translate(x + txvp, y + tyvp);
		noStroke();
		fill(250, 237, 203); //head
		ellipse(-2, 0, 40, 50);
		fill(255); //hair
		ellipse(0, -22, 35, 8);
		fill(255); //eyes
		ellipse(-10, -4, 8, 8);
		fill(0);
		ellipse(-10, -4, 4, 4);
		fill(255, 0, 0); //mouth
		ellipse(-12, 13, 8, 8);
		stroke(0);
		line(-25, 13, -40, 13);
		line(-25, 8, -40, 0);
		line(-25, 18, -40, 26);
		noStroke();

		//suit
		fill(255); //shirt
		rect(-15, 23, 25, 50);
		fill(0, 0, 255); //suit jacket
		rect(-8, 23, 18, 50);
		fill(255, 0, 0); //tie
		rect(-15, 23, 3, 30);
		fill(0); //shoes
		ellipse(-7, 133, 35, 15);
		fill(0, 0, 255); //pants
		rect(-15, 73, 25, 60);
		push(); //arm
		rotate(radians(40));
		fill(250, 237, 203);
		ellipse(-18, 45, 10, 10);
		fill(0, 0, 255);
		rect(-18, 40, 50, 10);
		pop();
		pop()
		}

//December global variables - firework coordinate arrays     
var xpos = 0;
var xcoord = [35, 25, 55, 200, 240, 400, 470, 440, 455, 230, 280, 415, 100, 280];
var ycoord = [25, 100, 350, 120, 150, 75, 45, 175, 300, 320, 365, 340, 215, 50];

function clickMonthDec() {
	//abstract clock to wait for the end of 2020
    if (keyCode === 187) {
        clearBkrd();
        backButton();
        frameRate(5);
    	background(0);
	    var sec = second();
	    var min = minute();
	    var hr = hour();
	    var d = day();
	    background(0);

	    //draw fireworks in the background
	    for (var i = 0; i < 14; i++) {
	        firework(xcoord[i], ycoord[i]);
	    }

	    push();
	    scale(0.5);
	    president(16*d, 40); //moves with day
	    pop();
	    decVirus(20*hr, 150); //hour
	    image(aprImg3, 8*min, 200, 80, 80); //minute
	    decHurricane(8*sec, 350); //second

	}
}

	//December helper functions
	function firework(x, y) { 
	    var r = random(255);
	    var g = random(255);
	    var b = random(255);
	    push();
	    translate(x, y);
	    stroke(r, g, b);
	    for (var i = 0; i < 12; i++) { //draw lines
	        push();
	        rotate(radians(i*30));
	        line(xpos, 0, xpos + 15, 0);
	        pop();
	    }

	    if (xpos <= 25) { //grow
	    xpos += 1;
	    }

	    else if (xpos > 25) { //reset
	        xpos = 0;
	    }
	    pop();
	}

	function decVirus(x, y) { //design taken from Shaun's virus object - I did not code
	        stroke('black');//body of virus
	        strokeWeight(2);
	        fill('red');
	        push();
	        translate(x, y);
	        circle(0, 0, 35);
	        strokeWeight(3);//stems of virus
	        var angle = 45;
	        for (let i = 0; i < 8; i++) {
	            rotate(radians(angle));
	            beginShape();
	            vertex(35/2 - 10, 0)
	            vertex(random(35/2 + 4, 35/2 + 8), random(-2, 2));
	            endShape(CLOSE);
	            ellipse(random(35/2 + 8, 35/2 + 6), random(1, 3), 11, 9);
	        }
	        pop();
	}

    function decHurricane(x, y) { //from October 
        push();
        translate(x, y);
        noStroke();
        fill(255, 0, 0);
        ellipse(0, 0, 30, 30);
        fill(230);
        ellipse(0, 0, 10, 10);

        //hurricane lines
        push(); 
        scale(0.7);
        translate(-40, 5);
        stroke(255, 0, 0);
        strokeWeight(5);
        noFill();
        beginShape();
        for (var i = 2; i <= 4; i += 0.1) {
            var y1 = Math.pow(2.6, i);
            vertex(i*25, -y1);
        }
        endShape();
        pop();
        push();
        scale(0.7);
        stroke(255, 0, 0);
        strokeWeight(5);
        noFill();
        translate(40, -5);
        rotate(radians(180));
        beginShape();
        for (var i = 2; i <= 4; i += 0.1) {
            var y1 = Math.pow(2.6, i);
            vertex(i*25, -y1);
        }
        endShape();
        pop();
        pop();
    }
      

The purpose of our project is to create an interactive calendar that displays important events, memes/jokes,
and or popular culture references to every month in 2020. Each program on its own is not very substantial,
but we aimed to incorporate as many programing elements from the semester as possible. It is a 2020 themed variety show!
The user-interface is a grid displaying the months of the year with instructions on how to access each month.
We have each month bound to a key, “1” through “=,” representing all 12 months.
When a particular key is pressed, the set of functions for the month run until the user presses the “esc” key to return to the main calendar.
The plans for my months are as follows:
Jan – Reference to the tension between the U.S. and North Korea at the tail end of 2019.
Feb – Pelosi Simulator: ripping President Trump’s speech at the State of the Union.
Mar – Object-oriented corona virus representation bouncing around a world map until it covers the U.S.
Apr – Something about Tiger King indeed.
May – Kim Jong Un hiding behind a podium after his health speculations .
Jun – President Trump removing protesters from St. John’s Church in Washington D.C.
We sincerely hope that 2021 is a much better year. Enjoy!

Project 15: Final Project

finalYeung2020Download
//stores all the changes
var changes={
    activism: false, //political poster on the wall, b
    cramps: false, //typing sound, c
    battery: false, //low battery, d
    voted: false, //i voted sticker on wall, e
    text: false, //text notif from friend to hangout, f
    delivery: false, //notif that grubhub is here, g
    canvasNotifs: false, //notif that new assignment was posted, h
    mask: false, //mask on wall, i
    handshake: false, //handshake homepage, j
    rust: false, //keys turn brown, k
    night: false, //outside window is night now, l
    maskBox: false, //box of masks appear on desk, m
    dino: false, //dino game, n
    zeroPercent: false, //canvas grade page with a 0, o
    parents: false, //knocking sound, p
    askText: false, //text notif to ask if you're okay, q
    grenell: false, //grenell petition, r
    netflix: false, //netflix home page, s
    tikTok: false, //tik tok home page, t
    unmuted: false, //eating sound, u
    chegg: false, //chegg home page, w
    pills: false, //pill bottle on desk, x
    muted: false, //zoom page, muted y
    zoomFatigue: false, //yawn sound, z
}

//triggers for sound
var fr1=0;
var fr2=0;
var fr3=0;
var fr4=0;

//triggers congrats
var fr5=0

//arrays to store letters and corresponding messages
var alphabet = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"];
var letterMessage = [
    "An optimistic start: you're kind of excited that spring break got extended by a week!\nyou'll be back on campus in no time", //no change
    "Black Lives Matter: you do whatever you can to help the cause",
    "Cramps: you've typed so much in the past few months that your fingers start cramping", //typing sound
    "Dying: crap, your battery is low",
    "Election: you sent in your mail-in ballot",
    "Friends: your friend asks you to hangout but you feel too guilty to do anything",
    "Grubhub: I don't feel like making food so I'll just waste $20 on a $10 meal",
    "Homework: homework assignments just seem to pile up, but you're so unmotivated",
    "I forgot a mask: you walked to the store but forgot your mask, so you had to come back",
    "Job Applications: you know you have to applying for internships,\nbut you just don't have the effort to",
    "Keys: you haven't gone outside in so long, your keys are rusting",
    "Long Hours: time seems nonexistent when you work from home",
    "Masks: your mom buys you a giant box of masks", 
    "No Internet: oh no! Your internet went out, time to play the dino game :(",
    "Oops, I forgot: without your friends to remind you,\nyou accidentally forget to do your homework",
    "Parents: even though you're in lecture,\nyour parents don't understand and still try to talk to you", //knocking sound
    "Questions: it seems like every two seconds someone's asking if you're okay",
    "Richard Grenell: you sign the petition to fire him,\neven though you're not sure if anything will happen",
    "Streaming: you feel like you've watched everything on Netflix in the past few months",
    "Tik Tok: you spend your time endlessly scrolling",
    "Unmuted: you forgot to mute yourself so your entire class heard you eat your lunch!", //eating sound
    "Vaccine: you're just hoping there's a vaccine in time for summer", //no change
    "Work: has homework always been this hard?",
    "Xanax: you start having panic attacks and your doctor prescribes you Xanax",
    "You're Muted: you try to answer a question in class but forget you're muted,\nso you just look stupid",
    "Zoom Fatigue: after hours on Zoom for lectures, you feel exhausted", //yawn sound
]

//images that need to be loaded
var blm;
var boxOfMasks;
var canvasNotification;
var cheggHomePage;
var dinoGame;
var grenellPetition;
var grubhubText;
var handshakeHomePage;
var hangOutText;
var iVotedSticker;
var lowBatteryNotif;
var netflixHomePage;
var questionText;
var tikTokHomePage;
var zeroPercentGrade;

//sounds that need to be loaded
var eating;
var knockKnock;
var tired;
var type;

function preload(){
    //loads images
    blm=loadImage("https://i.imgur.com/JFLSHwn.jpg");
    boxOfMasks=loadImage("https://i.imgur.com/XEQ2DIE.png");
    canvasNotification=loadImage("https://i.imgur.com/iI0fpJP.png");
    cheggHomePage=loadImage("https://i.imgur.com/hdPz4NX.png");
    dinoGame=loadImage("https://i.imgur.com/tvKCVyP.png");
    grenellPetition=loadImage("https://i.imgur.com/i7QTQyK.png");
    grubhubText=loadImage("https://i.imgur.com/YROzHtr.png");
    handshakeHomePage=loadImage("https://i.imgur.com/K36qX37.png");
    hangOutText=loadImage("https://i.imgur.com/Nqt81BJ.png");
    iVotedSticker=loadImage("https://i.imgur.com/SfQn4pk.png");
    lowBatteryNotif=loadImage("https://i.imgur.com/cC8hsTT.png");
    netflixHomePage=loadImage("https://i.imgur.com/N9BohE8.jpg");
    questionText=loadImage("https://i.imgur.com/rQHSMwT.png");
    tikTokHomePage=loadImage("https://i.imgur.com/DlDOeHF.png");
    zeroPercentGrade=loadImage("https://i.imgur.com/exTf7NY.png");
    zoomMeeting=loadImage("https://i.imgur.com/RcF2XKO.jpg");
    xanaxBottle=loadImage("https://i.imgur.com/EcRn3JI.png");
    maskMessage=loadImage("https://i.imgur.com/qR7W3rv.png");

    //loads sounds
    eating=loadSound("https://courses.ideate.cmu.edu/15-104/f2020/wp-content/uploads/2020/12/crunch.wav");
    knockKnock=loadSound("https://courses.ideate.cmu.edu/15-104/f2020/wp-content/uploads/2020/12/knock.wav");
    tired=loadSound("https://courses.ideate.cmu.edu/15-104/f2020/wp-content/uploads/2020/12/yawn.wav");
    type=loadSound("https://courses.ideate.cmu.edu/15-104/f2020/wp-content/uploads/2020/12/typing.wav");
}
//setup functions
function setup() {
    createCanvas(600, 550);
    useSound();
    frameRate(1);
}

function soundSetup(){
    eating.setVolume(0.5);
    knockKnock.setVolume(0.5);
    tired.setVolume(0.5);
    type.setVolume(0.5);
}

function draw() {
    covid(); //changes the booleans
    drawRoom(); //draws the room

    typeAlphabet(); //types the alphabet and messages
    typeMessages();

    ifStatements(); //adds all the if statements to make the images and sounds appear/play
}

function covid(){ //when a key is pressed, boolean changes
    if (key == 'b') {
        changes.activism =true;
    }
    if (key == 'c') {
        changes.cramps =true;
    }
    if (key == 'd') {
        changes.battery =true;
    }
    if (key == 'e') {
        changes.voted =true;
    }
    if (key == 'f') {
        changes.text =true;
    }
    if (key == 'g') {
        changes.delivery =true;
    }
    if (key == 'h') {
        changes.canvasNotifs =true;
    }
    if (key == 'i') {
        changes.mask =true;
    }
    if (key == 'j') {
        changes.handshake =true;
    }
    if (key == 'k') {
        changes.rust =true;
    }
    if (key == 'l') {
        changes.night =true;
    }
    if (key == 'm') {
        changes.maskBox =true;
    }
    if (key == 'n') {
        changes.dino =true;
    }
    if (key == 'o') {
        changes.zeroPercent =true;
    }
    if (key == 'p') {
        changes.parents =true;
    }
    if (key == 'q') {
        changes.askText =true;
    }
    if (key == 'r') {
        changes.grenell =true;
    }
    if (key == 's') {
        changes.netflix =true;
    }
    if (key == 't') {
        changes.tikTok =true;
    }
    if (key == 'u') {
        changes.unmuted =true;
    }
    if (key == 'w') {
        changes.chegg =true;
    }
    if (key == 'x') {
        changes.pills =true;
    }
    if (key == 'y') {
        changes.muted =true;
    }
    if (key == 'z') {
        changes.zoomFatigue =true;
    }
}

function drawRoom(){
    background(230, 234, 245);
    noStroke();
    fill(74, 40, 2);
    rect(0, 350, 600, 130);
    drawWindow();
    fill(77, 77, 77);
    rect(0, 200, 400, 280);
    fill(0);
    rect(0, 215, 385, 270);
    fill(220);
    rect(0, 425, 600, 175);
    drawKey();
    push();
    translate(150, 40);
    scale(0.15);
    drawClock();
    pop();

    //draws sign with instructions
    fill(255, 255, 204);
    rect(15, 15, 80, 70);

    fill(0, 0, 51);
    textAlign(CENTER);
    textSize(12);
    text("Press keys\nin ABC order\nto finish", 55, 35);

}

function drawWindow(){
    //changes background to show time elapsed
    if (changes.night==true){
        fill(0, 20, 37);
        rect(300, 40, 300, 250);
    }
    if (changes.night==false){
        fill(81, 174, 255);
        rect(300, 40, 300, 250);
    }

    //grass
    fill(0, 102, 0);
    rect(300, 220, 300, 70);

    //mountains
    stroke(135, 126, 138);
    strokeWeight(1);
    for (var x=300; x<width; x++){
        var l=x*0.01;
        var y=map(noise(l), 0, 1, 170, 220);
        line(x, y, x, 220);
    }

    //window pane
    noFill();
    stroke(255);
    strokeWeight(15);
    rect(300, 40, 350, 250);
    strokeWeight(10);
    line(300, 165, 600, 165);
    line(550, 40, 550, 290);
    noStroke();  
}

function drawKey(){
    //changes color of key
    if (changes.rust==false){
        fill(180); //grey
    }
    if (changes.rust==true){
        fill(204, 102, 0) //orange
    }

    //draws key
    push();
    scale(0.5);
    translate(1000, 800);
    rotate(radians(10));
    ellipse(0, 0, 20, 40);
    rect(0, -5, 60, 10);
    //draws key's spokes(?)
    var keyLengths=[15, 20, 13];
    for (var i=0; i<4; i++){
        rect(25+(i*10), 0, 6, keyLengths[i]);
    }
    pop();

}

function ifStatements(){ //inputs images and sounds for the key presses
    //images triggered
    if (changes.activism==true){
        image(blm, 45, 100, 70, 91);
    }
    if (changes.battery==true){
        image(lowBatteryNotif, 185, 215, 200, 52);
    }
    if (changes.voted==true){
        image(iVotedSticker, 225, 150, 50, 50);
    }
    if (changes.text==true){
        image(hangOutText, 185, 215, 200, 52);
    }
    if (changes.delivery==true){
        image(grubhubText, 185, 215, 200, 52);
    }
    if (changes.canvasNotifs==true){
        image(canvasNotification, 185, 215, 200, 52);
    }
    if (changes.mask==true){
        image(maskMessage, 185, 215, 200, 52);
    }
    if (changes.handshake==true){
        image(handshakeHomePage, 0, 215, 385, 211);
    }
    if (changes.maskBox==true){
        image(boxOfMasks, 500, 300, 150, 113);
    }
    if (changes.dino==true){
        image(dinoGame, 0, 215, 385, 211);
    }
    if (changes.zeroPercent==true){
        image(zeroPercentGrade, 0, 215, 385, 211);
    }
    if (changes.askText==true){
        image(questionText, 185, 215, 200, 52);
    }
    if (changes.grenell==true){
        image(grenellPetition, 0, 215, 385, 211);
    }
    if (changes.netflix==true){
        image(netflixHomePage, 0, 215, 385, 211);
    }
    if (changes.tikTok==true){
        image(tikTokHomePage, 0, 215, 385, 211);
    }
    if (changes.pills==true){
        image(xanaxBottle, 410, 340, 25, 44);
    }
    if (changes.muted==true){
        image(zoomMeeting, 0, 215, 385, 211);
    }
    if (changes.chegg==true){
        image(cheggHomePage, 0, 215, 385, 211);
    }

    //sounds triggered
    if (changes.cramps==true){
        fr1++;
        if (fr1==1){
            type.play();
        }
        fr1++;
        
    }
    if (changes.parents==true){
        fr2++;
        if (fr2==1){
            knockKnock.play();
        }
        fr2++;
    }
    if (changes.unmuted==true){
        fr3++;
        if (fr3==1){
            eating.play();
        }
        fr3++;
    }
    if (changes.zoomFatigue==true){
        fr4++;
        if (fr4==1){
            tired.play();
        }
        fr4++;

    }

    //triggers the congrats message
    if (changes.activism & changes.cramps && changes.voted && changes.text && changes.delivery && changes.canvasNotifs && changes.mask && changes.handshake && changes.rust && changes.night && changes.maskBox && changes.dino && changes.zeroPercent && changes.parents && changes.askText && changes.grenell && changes.netflix && changes.tikTok && changes.unmuted && changes.chegg && changes.pills && changes.muted && changes.zoomFatigue){
        fr5++;
        if (fr5>5){
            textAlign(CENTER);
            textSize(25);
            text("Congrats, you finished 2020!", width/2, height-50);
        }
    }
    
}

//types the alphabet on screen
function typeAlphabet() {
    for (var i = 0; i < 26; i ++) {
        textAlign(CENTER);
        textSize(20);
        noStroke();
        var yLocation = 540;
        var x = map(i, 0, alphabet.length, 50, width - 30);
        if (keyCode === 65 + i) { //when key is down, letter turns grey
            fill(100);
            text(alphabet[i], x, yLocation);
        } else {
            fill(0, 0, 51);
            text(alphabet[i], x, yLocation);
        } 
    }
}

function keyReleased() { //replaces already clicked letters and their info with spaces in the respective arrays
    for (var i = 0; i < 26; i ++) {
        if (keyCode == 65 + i) {
            alphabet.splice(i, 1, " ");
            letterMessage.splice(i, 1, " ");
        }       
    }
}

//types the messages on screen
function typeMessages() {
    textAlign(CENTER);
    textSize(15);
    fill(0, 0, 51);
    for (var i = 0; i < 26; i ++) {
        if (keyCode === 65 + i) {
            text(letterMessage[i], width / 2, height - 60);  
        } 
    }   
}

//draws accurate clock on the wall
function drawClock(){
    //from https://p5js.org/examples/input-clock.html
    var cx;
    var cy;
    var secR;
    var minR;
    var hrR;
    var cD;
  
    var radius=width/2;
    secR=radius*0.71;
    minR=radius*0.6;
    hrR=radius*0.5;
    cD=radius*1.7
  
    cx=width/2;
    cy=height/2;
  
    noStroke();
    fill(15);
    ellipse(cx, cy, cD+25, cD+25);
    fill(255);
    ellipse(cx, cy, cD, cD);
  
    var s=map(second(), 0, 60, 0, TWO_PI)-HALF_PI;
    var m=map(minute()+norm(second(), 0, 60), 0, 60, 0, TWO_PI)-HALF_PI;
    var h=map(hour()+norm(minute(), 0, 60), 0, 24, 0, TWO_PI*2)-HALF_PI;
  
    stroke(0);
    strokeWeight(1);
    line(cx, cy, cx+cos(s)*secR, cy+sin(s)*secR);
    strokeWeight(2);
    line(cx, cy, cx+cos(m)*minR, cy+sin(m)*minR);
    strokeWeight(4);
    line(cx, cy, cx+cos(h)*hrR, cy+sin(h)*hrR);
  
    strokeWeight(2);
    beginShape(POINTS);
    for(var i=0; i<360; i+=6){
        var angle=radians(i);
        var x=cx+cos(angle)*secR;
        var y=cy+sin(angle)*secR;
        vertex(x, y);
    }
    endShape();
  }

My final project was inspired by working from home as a full time student last semester and this semester. Like many other students, I experienced a lot of difficulties and setbacks we don’t usually have at school and I wanted to show all the tiny things that happen to us everyday. I also wanted it to reflect the political unrest that was happening at the same time due to the rise of the Black Lives Matter movements, the election, and for CMU students the hiring of Richard Grenell.
My program is interactive and each change is triggered by the keyboard. Users are supposed to follow the alphabet and something will change on the screen or a sound will be played. Since there are some sounds, you will need to use a localhost in order to hear them or view it from WordPress.

Final Project – Survive 2020 Game

Our project is inspired by the game Flappy Bird. In our rendition, 2020 events are the obstacles on the pipes and the goal is to “survive” 2020. The character moves up when you hit the letter ‘m’, the game ends if you hit one of the pipes, hit the ground or if you win by passing 12 pairs of pipes. If you lose by hitting a pipe or win you can play the game again, but if you hit the ground you lose and cannot restart the game. The two sounds you hear are the bounce when you move the character and the clash when the character hits one of the pipes. Based on which pipe you hit, you see a different “game over” message. We chose a darker color scheme and used a fire in the background to match the mood of 2020. If we had more time with this project, we would add a webcam function so that the character would be the user’s face instead of just a smiley face. Overall, this project was definitely challenging but also really fun to create.

final project
/* 
 * Final Project 
 * Rishi Karthikeyan and Amy Lee 
 * rkarthik and amyl2
 * Section B 
 */ 

// Run a local server to hear sounds used 
// Press the letter m to control character
// The game ends if the character hits the ground or the pipes 
// If you lose by hitting a pipe or win you can play the game again 
// but if you hit the ground you lose and cannot restart the game

var score = 0;
var count = 0;
var faceX = 50; 
var faceY = 200; 
var hitPipe = false; 
var endGame = false; 
var gameOn = true;
var gameStart = true;
var characterOn = true;
var pipes = []; 
var fire = [];
var pipeImages = []; // an array to store the images 
var factImages = []; // an array to store the dates between the pipes 
var gameOverImages = []; // an array to store the customized game over images 

var timeline1 = ["1/1/20", "1/16/20", "1/19/20", "2/2/20", "3/11/20", 
    "3/19/20", "3/20/20", "4/1/20", "5/1/20", "5/26/20", "11/6/20", "11/7/20"]

var timeline2=["Australian Bush Fire","Trump Impeached","COVID-19","Superbowl",
    "Parasite Wins Oscars","Zoom University","Tiger King","Royal Family Split",
    "Murder Hornets", "BLM Movement", "Election", "First Female VP Elect"]

function preload() {
    // Circular images that go in the pipes 
    var filenames = []; 
    filenames[0] = "https://i.imgur.com/tP1n00I.png"; // Fire 
    filenames[1] = "https://i.imgur.com/sY9uWvm.png"; // Trump 
    filenames[2] = "https://i.imgur.com/lCBeEEt.png"; // Covid 
    filenames[3] = "https://i.imgur.com/3Rckn2m.png"; // Superbowl 
    filenames[4] = "https://i.imgur.com/ul9jOdN.png"; // Oscar 
    filenames[5] = "https://i.imgur.com/iWRAmux.png"; // Zoom 
    filenames[6] = "https://i.imgur.com/dbYhauj.png"; // Tiger King
    filenames[7] = "https://i.imgur.com/lVbGhGa.png"; // Meg and Harry 
    filenames[8] = "https://i.imgur.com/U1PoDE5.png"; // Hornets 
    filenames[9] = "https://i.imgur.com/nqwizdc.png"; // BLM
    filenames[10] = "https://i.imgur.com/xtEZvMR.png"; // Election 
    filenames[11] = "https://i.imgur.com/1lZjhEQ.png"; // Kamala

    for (var i = 0; i < filenames.length; i ++) {
        pipeImages.push(loadImage(filenames[i])); 
    }

    // Displays game over message based on which pipe the character dies on
    var filenames2 = []; 
    filenames2[0] = "https://i.imgur.com/ibfDcOO.png"; // Fire  
    filenames2[1] = "https://i.imgur.com/vFpcofS.png"; // Trump 
    filenames2[2] = "https://i.imgur.com/NMyD9W2.png"; // Covid 
    filenames2[3] = "https://i.imgur.com/aU3iUST.png"; // Superbowl 
    filenames2[4] = "https://i.imgur.com/hqLtxr4.png"; // Oscar 
    filenames2[5] = "https://i.imgur.com/59MSAMG.png"; // Zoom 
    filenames2[6] = "https://i.imgur.com/ArzVHYU.png"; // Tiger King
    filenames2[7] = "https://i.imgur.com/up0miQL.png"; // Meg and Harry 
    filenames2[8] = "https://i.imgur.com/pSRx5bC.png"; // Hornets 
    filenames2[9] = "https://i.imgur.com/EzfHYCr.png"; // BLM
    filenames2[10] = "https://i.imgur.com/wJvHY17.png"; // Election 
    filenames2[11] = "https://i.imgur.com/929AM73.png"; // Kamala

    for (var i = 0; i < filenames2.length; i ++) {
        gameOverImages.push(loadImage(filenames2[i])); 
    }

    // Load sounds for when the character moves or hits the pipes 
    characterSound = loadSound("https://courses.ideate.cmu.edu/15-104/f2020/wp-content/uploads/2020/12/bounce.wav");
    clashSound = loadSound("https://courses.ideate.cmu.edu/15-104/f2020/wp-content/uploads/2020/12/clash.wav"); 
}

function setup() {
    createCanvas(450, 400);
    background(12, 22, 24);
    imageMode(CENTER); 
    useSound();

    if (gameOn == true) {
        fire.push(makeFire());
        pipes.push(makePipes());
    } 
}

function soundSetup() { 
    // Set the volume for the sound effects 
    characterSound.setVolume(0.01);
    clashSound.setVolume(0.05); 
}

function draw() {
    background(12, 22, 24);
    gradientSky();

    if (gameOn == true) {
        // Start the count once the game is on 
        count++
        // Display & add fire
        updateAndDisplayFire(); 
        if (count % 50 == 10){
            fire.push(makeFire()); 
        }
        updateAndDisplayPipes();
        // Add new pipes 
        if (count % 120 == 0){
            if (gameOn == true) {
            }

            if (pipes.length < 12) {
                pipes.push(makePipes()); 
            }

            if (count > 300) {
                score += 150;
            }
        }
    }

    // Score tracker  
    textSize(15);
    fill(72,160,141);
    noStroke();
    text('SCORE ' + score, 50, 23);

    drawFace(); 

    if (count >= 1690){ 
        gameOn = false; 
    } 

    if (gameOn == false) {
        gameWon();
    }

    if (hitPipe == true){
        gameOver(round((count/120) - ((120*3)/120))); 
    }
    
}

function gradientSky() {
    // Background color gradient 
    var darkCol = color(0,12,15); 
    var lightCol = color(14,38,39); 
    for (var y = 0; y < height; y ++){
        var backG = map(y, 0, height, 0, 1); 
        var backGColor = lerpColor(darkCol, lightCol, backG); 
        stroke(backGColor); 
        line(0, y, width, y); 
    }

    // Fire Embers 
    for (var i = 0; i < 35; i++) {
        strokeWeight(4);
        if (round(random(1)) == 0 ) {
            stroke(148, 67, 43);
        } else {
            stroke(81, 33, 22);
        }
        point(random(0,width), random(-0, height));
    }
}

// *************** FIRES *************** //
function updateAndDisplayFire(){
    // Update the fire's positions, and display them.
    for (var i = 0; i < fire.length; i++){
        fire[i].move();
        fire[i].draw();
    }
}

// Method to update position of fire every frame
function fireMove() {
    this.x += this.speed;
}

// Draw the fire 
function fireDraw() {
    push();
    translate(0, height - 220);
    scale(1.2, 1.75);
    noStroke();
    fill(81, 33, 22);   //red fire
        beginShape();
        vertex(this.x, this.y + 125);
        vertex(this.x, this.y  + 115);
        vertex(this.x + 5, this.y  + 115);
        curveVertex(this.x + 4, this.y  + 113);
        curveVertex(this.x + 3, this.y  + 112);
        curveVertex(this.x + 3, this.y  + 108);
        curveVertex(this.x + 5, this.y  + 102);
        curveVertex(this.x + 9, this.y  + 98);
        vertex(this.x + 18 + random(-1, 1), this.y + 93+ random(-1, 1));

        curveVertex(this.x + 17, this.y  + 110);
        curveVertex(this.x + 21, this.y  + 112);
        curveVertex(this.x + 31, this.y  + 109);
        curveVertex(this.x + 31, this.y  + 102);
        curveVertex(this.x + 25, this.y  + 95);
        curveVertex(this.x + 24, this.y  + 89);
        curveVertex(this.x + 27, this.y  + 83);
        curveVertex(this.x + 34, this.y  + 77);
        curveVertex(this.x + 40, this.y  + 70);
        curveVertex(this.x + 34, this.y  + 56);
        vertex(this.x + 30 + random(-1, 1), this.y  + 53 + random(-1, 1));

        curveVertex(this.x + 40, this.y  + 56);
        curveVertex(this.x + 50, this.y  + 64);
        curveVertex(this.x + 48, this.y  + 75);
        curveVertex(this.x + 41, this.y  + 83);
        curveVertex(this.x + 38, this.y  + 90);
        curveVertex(this.x + 40, this.y  + 98);
        curveVertex(this.x + 49, this.y  + 99);
        curveVertex(this.x + 52, this.y  + 95);
        curveVertex(this.x + 48, this.y  + 90);
        curveVertex(this.x + 48, this.y  + 84);
        vertex(this.x + 55 + random(-1, 1), this.y  + 75 + random(-1, 1));

        curveVertex(this.x + 54, this.y  + 81);
        curveVertex(this.x + 56, this.y  + 89);
        curveVertex(this.x + 60, this.y  + 97);
        curveVertex(this.x + 56, this.y  + 104);
        curveVertex(this.x + 62, this.y  + 117);
        curveVertex(this.x + 72, this.y  + 118);
        curveVertex(this.x + 80, this.y  + 112);
        curveVertex(this.x + 75, this.y  + 99);
        curveVertex(this.x + 68, this.y  + 92);
        curveVertex(this.x + 63, this.y  + 83);
        curveVertex(this.x + 70, this.y  + 63);
        curveVertex(this.x + 84, this.y  + 54);
        vertex(this.x + 94 + random(-1, 1), this.y  + 50 + random(-1, 1));

        curveVertex(this.x + 85, this.y  + 56);
        curveVertex(this.x + 77, this.y  + 65);
        curveVertex(this.x + 73, this.y  + 73);
        curveVertex(this.x + 77, this.y  + 77);
        curveVertex(this.x + 87, this.y  + 75);
        vertex(this.x + 89 + random(-1, 1), this.y  + 63 + random(-1, 1));

        curveVertex(this.x + 93, this.y  + 68);
        curveVertex(this.x + 93, this.y  + 78);
        curveVertex(this.x + 87, this.y  + 86);
        curveVertex(this.x + 81, this.y  + 93);
        curveVertex(this.x + 87, this.y  + 99);
        curveVertex(this.x + 92, this.y  + 99);
        curveVertex(this.x + 97, this.y  + 92);
        curveVertex(this.x + 94, this.y  + 87);
        curveVertex(this.x + 94, this.y  + 84);
        vertex(this.x + 98 + random(-1, 1), this.y  + 77 + random(-1, 1));

        curveVertex(this.x + 101, this.y  + 85);
        curveVertex(this.x + 104, this.y  + 89);
        curveVertex(this.x + 107, this.y  + 97);
        curveVertex(this.x + 104, this.y  + 104);
        curveVertex(this.x + 101, this.y  + 110);
        curveVertex(this.x + 109, this.y  + 115);

        vertex(this.x + 113, this.y  + 115);
        vertex(this.x + 113, this.y  + 128);
        endShape(CLOSE);
    pop();

    push();
    translate(0, height - 125);
    scale(1, 1);
    noStroke();
    fill(148, 67, 43);  //orange fire   
        beginShape();
        vertex(this.x, this.y + 125);
        vertex(this.x, this.y  + 115);
        vertex(this.x + 5, this.y  + 115);
        curveVertex(this.x + 4, this.y  + 113);
        curveVertex(this.x + 3, this.y  + 112);
        curveVertex(this.x + 3, this.y  + 108);
        curveVertex(this.x + 5, this.y  + 102);
        curveVertex(this.x + 9, this.y  + 98);
        vertex(this.x + 18 + random(-1, 1), this.y + 93+ random(-1, 1));

        curveVertex(this.x + 17, this.y  + 110);
        curveVertex(this.x + 21, this.y  + 112);
        curveVertex(this.x + 31, this.y  + 109);
        curveVertex(this.x + 31, this.y  + 102);
        curveVertex(this.x + 25, this.y  + 95);
        curveVertex(this.x + 24, this.y  + 89);
        curveVertex(this.x + 27, this.y  + 83);
        curveVertex(this.x + 34, this.y  + 77);
        curveVertex(this.x + 40, this.y  + 70);
        curveVertex(this.x + 34, this.y  + 56);
        vertex(this.x + 30 + random(-1, 1), this.y  + 53 + random(-1, 1));

        curveVertex(this.x + 40, this.y  + 56);
        curveVertex(this.x + 50, this.y  + 64);
        curveVertex(this.x + 48, this.y  + 75);
        curveVertex(this.x + 41, this.y  + 83);
        curveVertex(this.x + 38, this.y  + 90);
        curveVertex(this.x + 40, this.y  + 98);
        curveVertex(this.x + 49, this.y  + 99);
        curveVertex(this.x + 52, this.y  + 95);
        curveVertex(this.x + 48, this.y  + 90);
        curveVertex(this.x + 48, this.y  + 84);
        vertex(this.x + 55 + random(-1, 1), this.y  + 75 + random(-1, 1));

        curveVertex(this.x + 54, this.y  + 81);
        curveVertex(this.x + 56, this.y  + 89);
        curveVertex(this.x + 60, this.y  + 97);
        curveVertex(this.x + 56, this.y  + 104);
        curveVertex(this.x + 62, this.y  + 117);
        curveVertex(this.x + 72, this.y  + 118);
        curveVertex(this.x + 80, this.y  + 112);
        curveVertex(this.x + 75, this.y  + 99);
        curveVertex(this.x + 68, this.y  + 92);
        curveVertex(this.x + 63, this.y  + 83);
        curveVertex(this.x + 70, this.y  + 63);
        curveVertex(this.x + 84, this.y  + 54);
        vertex(this.x + 94 + random(-1, 1), this.y  + 50 + random(-1, 1));

        curveVertex(this.x + 85, this.y  + 56);
        curveVertex(this.x + 77, this.y  + 65);
        curveVertex(this.x + 73, this.y  + 73);
        curveVertex(this.x + 77, this.y  + 77);
        curveVertex(this.x + 87, this.y  + 75);
        vertex(this.x + 89 + random(-1, 1), this.y  + 63 + random(-1, 1));

        curveVertex(this.x + 93, this.y  + 68);
        curveVertex(this.x + 93, this.y  + 78);
        curveVertex(this.x + 87, this.y  + 86);
        curveVertex(this.x + 81, this.y  + 93);
        curveVertex(this.x + 87, this.y  + 99);
        curveVertex(this.x + 92, this.y  + 99);
        curveVertex(this.x + 97, this.y  + 92);
        curveVertex(this.x + 94, this.y  + 87);
        curveVertex(this.x + 94, this.y  + 84);
        vertex(this.x + 98 + random(-1, 1), this.y  + 77 + random(-1, 1));

        curveVertex(this.x + 101, this.y  + 85);
        curveVertex(this.x + 104, this.y  + 89);
        curveVertex(this.x + 107, this.y  + 97);
        curveVertex(this.x + 104, this.y  + 104);
        curveVertex(this.x + 101, this.y  + 110);
        curveVertex(this.x + 109, this.y  + 115);

        vertex(this.x + 113, this.y  + 115);
        vertex(this.x + 113, this.y  + 128);
        endShape(CLOSE);
    pop();
}

function makeFire() {
    var fire = {x: width,
                y: 0,
                speed: -2,
                move: fireMove,
                draw: fireDraw}
    return fire;
}

// *************** CHARACTER *************** //
function drawFace() {
    if (characterOn == true) { 
        push(); 
        // Head 
        noStroke();
        fill(72,160,141); 
        ellipse(faceX, faceY, 30, 30); 
        // Eyes 
        fill(12, 22, 24); 
        ellipse(faceX - 9, faceY - 1, 3.5, 3.5); 
        ellipse(faceX + 9, faceY - 1, 3.5, 3.5); 
        // Mouth 
        noFill(); 
        stroke(12, 22, 24); 
        strokeWeight(1); 
        arc(faceX, faceY, 5, 5, 0, PI, OPEN);
        pop(); 
        faceY += 1; 

        // Keep face from going off of the canvas
        if (faceY < 15){
            faceY += 5;
        }
        // Game over if you hit the bottom of the canvas
        if (faceY > height - 15){
           hitBottomGameOver();
        }
    }
}

// *************** PIPES *************** //
function updateAndDisplayPipes(){

    // Update the pipe's positions, and display them
    for (var i = 0; i < pipes.length; i++) {
        pipes[i].move();

        // Game over if face hits the pipes 
        if (((faceY < pipes[i].pipeHeight + 30) & (faceX > pipes[i].x && 
            faceX < pipes[i].x + pipes[i].pipeWidth)) || ((faceY > 400 - 
            ((400 - (pipes[i].pipeHeight + (200 - pipes[i].pipeHeight) + 
            (122 - (200 - pipes[i].pipeHeight)))) + 55)) && 
            (faceX > pipes[i].x && faceX < pipes[i].x + pipes[i].pipeWidth))){

            hitPipe = true; 
            clashSound.play();
        }

        if (gameStart == true) {
            pipes[i].draw();
        }

        // Display image on pipe 
        pipes[i].imageNumber = i;
        if ( pipes[i].imageNumber > 11) {
            pipes[i].imageNumber = 0;
        }

        // Display timeline date in between pipes 
        pipes[i].timelineNumber = i; 
        if ( pipes[i].timelineNumber > 11) {
            pipes[i].timelineNumber = 0;
        }
    } 
}

// Method to update position of pipe every frame
function pipesMove() {
    this.x += this.speed;
}
    
// Draw the pipe 
function pipesDraw() {
    var pipe1Height = this.pipeHeight - 30; 
    var pipe2Height = 400 - (this.pipeHeight + (200 - this.pipeHeight) + 
                    (126 - (200 - this.pipeHeight)) ); 

    fill(34,79,82); 
    noStroke(); 

    // Top Pipe 
    rect(this.x, -30, this.pipeWidth, this.pipeHeight); 
    ellipse(this.x + 40, pipe1Height, this.pipeWidth, this.pipeWidth); 
    image(pipeImages[this.imageNumber], this.x + 40, pipe1Height, 60, 60); 

    // Fact in middle of pipe 
    textSize(15);
    textAlign(CENTER); 
    fill(148, 67, 43);
    text(timeline1[this.timelineNumber], this.x + 40, (pipe1Height + 
        ((400 - ((pipe1Height) + (pipe2Height)))/2)) - 2);
    text(timeline2[this.timelineNumber], this.x + 40, (pipe1Height + 
        ((400 - ((pipe1Height) + (pipe2Height)))/2)) + 15);

    // Bottom Pipe 
    push(); 
    fill(34,79,82); 
    translate(0,400); 
    rect(this.x, -pipe2Height, this.pipeWidth, pipe2Height); 
    ellipse(this.x + 40, -pipe2Height, this.pipeWidth, this.pipeWidth);
    image(pipeImages[this.imageNumber], this.x + 40, -pipe2Height, 60, 60);     
    pop(); 
}

function makePipes() {
    var pipe = {x: 650,
                pipeWidth: 80, 
                pipeHeight: random(130, 200),
                speed: -2, 
                move: pipesMove,
                draw: pipesDraw,
                imageNumber: 0,
                timelineNumber: 0
                }
    return pipe;
}

function keyPressed() {
    if (key == 'm'){ 
        faceY -= 20; 

        if (characterOn == true) {
            characterSound.play();
        }
    }
}

// Function that is run when character hits the bottom of the canvas 
function hitBottomGameOver() {
    push();
    gradientSky();

    noStroke();
    fill(72,160,141);
    rectMode(CENTER);
    rect(width/2, height/2, 227, 55);
    textAlign(CENTER);
    textSize(20);
    fill(148, 67, 43);
    text(' Y O U  L O S T  2 0 2 0 ! ', width/2, height/2);

    characterOn = false;
    noLoop();
    pop();
}

// Function that is run when the character hits the pipe 
function gameOver(pipeNumber){
            // Display the gradient sky
            gradientSky();

            // Display game over image depending on which pipe was hit 
            image(gameOverImages[pipeNumber], width/2, height/2, 250, 250); 

            // Display play again button 
            fill(148, 67, 43);
            stroke(180, 67, 43);
            strokeWeight(2);
            push();
            rectMode(CENTER);
            rect(width/2, height/2 + 160, 110, 35);
            pop();
            textSize(15);
            noStroke();
            fill(255);
            text('PLAY AGAIN', width/2, height/2 + 165);

            gameStart = false;
            characterOn = false;
            hitPipe = true; 
            gameOn = false;
}

// Function that is run when the character wins the entire game 
function gameWon() {
    push();

    // "YOU WON 2020" sign in center of screen 
    noStroke();
    fill(72,160,141);
    rectMode(CENTER);
    rect(width/2, height/2, 225, 55);
    textAlign(CENTER);
    textSize(20);
    fill(148, 67, 43);
    text(' Y O U  W O N  2 0 2 0 ! ', width/2, height/2);

    // Play again button
    fill(148, 67, 43);
    stroke(180, 67, 43);
    strokeWeight(2);
    rect(width/2, height/2 + 55, 110, 35);
    textSize(15);
    noStroke();
    fill(255);
    text('PLAY AGAIN', width/2, height/2 + 55);

    characterOn = false;
    pop();
}

function mousePressed() {
    // Press to play again after a user wins the game 
    if (count >= 1689 & gameOn == false) {
        if (mouseX > width/2 - 55 && mouseX < width/2 + 55 && 
            mouseY < height/2 + 72.5 && mouseY > height/2 + 37.5) {
                gameOn = true;
                gameStart = true;
                characterOn = true;
                endGame = false; 
                count = -50;
                score = 0; 
                pipes = []; 
                fire = [];
        }
    }

    // Press to play again when user lost the game by hitting a pipe 
    if (hitPipe == true) {
        if (mouseX > width/2 - 55 & mouseX < width/2 + 55 && 
            mouseY < height/2 + 177.5 && mouseY > height/2 + 142.5) {
                hitPipe = false; 
                endGame = false; 
                gameStart = true;
                gameOn = true; 
                characterOn = true;
                count = -50;
                score = 0; 
                pipes = []; 
                fire = [];
        }
    }
}





original proposal mockup

***on our Autolab submission we use the up arrow to control the character but here we used the letter m because with the up arrow it would move the whole page up and not just the canvas***

Final Project: survive Covid

sketch

Introduction:
This is a survive Covid game. The goal is to help a ninja who’s trapped in a covid world avoid viruses, obtain masks, and eat sushi! I want to make this educational game to show that to fight covid one needs to wear a mask, stay safe, and eat well. The game is easy to play and has a lighthearted atmosphere. People can play this browser game to kill time and have fun.

Guidelines:
There will be viruses coming from the right of the screen and the player needs to press the space to make the ninja jump over the virus barricades. The player loses if the ninja hits the viruses for more than three times. The player gets an extra life when the ninja gets a mask. The player gets 20 extra points when the ninja eats a sushi. The game gets harder as the player gets higher scores.

Applications:
If I have more time, I wish to implement a shop feature which allows the player to buy new characters and items such as sanitizers and napkins, making the game more interesting.

//Name: Heying Wang  Andrew id: heyingw
//Section B
var ninja;
var ninjaSize=50;
var sushiSize=50;
var virus;
var virusSize=40;
var viruses=[];
var virusImages=[];
var clouds=[];
var sushiArray=[];
//The player has an initial score of 0 and life of 3
var score=0;
var life=3;
var timer=0;

var circleColor = [];
var r=50; //radius
var theta=0; 
var startAngles=[];
var xvalues=[];
var yvalues=[];


function preload() {
    //ninja image
    ninjaImage=loadImage('https://i.imgur.com/kpI63Vj.png')
    //background image
    bgImage=loadImage("https://i.imgur.com/S5mfVFp.jpg");
    //three kinds of covid virus
    virusImage1=loadImage("https://i.imgur.com/SjGhpnK.png")
    virusImage2=loadImage("https://i.imgur.com/AKjfL9n.png")
    virusImage3=loadImage("https://i.imgur.com/nYvztEk.png")
    virusImages.push(virusImage1);
    virusImages.push(virusImage2);
    virusImages.push(virusImage3);

    cloudImg=loadImage("https://i.imgur.com/fLez1dg.png");
    sushiImg=loadImage("https://i.imgur.com/oz3ud5W.png");

    //load the sounds
    game=loadSound('https://courses.ideate.cmu.edu/15-104/f2020/wp-content/uploads/2020/12/game.wav');
    sushiSound=loadSound('https://courses.ideate.cmu.edu/15-104/f2020/wp-content/uploads/2020/12/sushi.wav');
    jump=loadSound('https://courses.ideate.cmu.edu/15-104/f2020/wp-content/uploads/2020/12/jump.wav');
    mask=loadSound('https://courses.ideate.cmu.edu/15-104/f2020/wp-content/uploads/2020/12/mask.wav');
}


function setup() {
    createCanvas(600, 250);
    useSound();
    //set up with constructors
    ninja=makeNinja(20,height-100,ninjaImage,ninjaSize);
    virus=makeVirus(width-100,height-50,virusSize,random(virusImages));
    viruses.push(virus);
    sushi=makeSushi(width*3,100,sushiImg,sushiSize);
    sushiArray.push(sushi); 

    for (var i = 0; i < 2; i++){
        var rx = random(width,width*2);
        clouds[i] = makeCloud(rx);
    }

    for (var i = 0; i < 12; i++) {
        circleColor[i] = color(random(0,256), random(0, 256), random(0, 256),120);
        startAngles[i] = i*30;
    }
    
}

//set up the sounds
function soundSetup() { 
    game.loop();
    game.setVolume(0.5);
    jump.setVolume(0.1);

    
 
}



function draw() {
    //set a timeCounter
    timer+=1;
    console.log(timer);
    image(bgImage,0,0,600,250);
    fill(255);
    textSize(20);
    text("score: "+score,470,30);
    text("life: "+life,30,30);
    push();
    drawCircles();
    pop();
    //draw ninja. Move ninja
    ninja.show();
    ninja.move();
    for(var i=0;i<sushiArray.length;i++){
        sushiArray[i].show();
        sushiArray[i].move();
    }

    //draw and move every virus in the viruses array
    if(timer>150){
        for(var i=0;i<viruses.length;i++){
            viruses[i].show();
            viruses[i].move();
        }
    }
    console.log(timer);

    //level up as the player gets higher scores
    if(score>50){
        virusSize=50;
    }
    else if(score>120){
        ninjaSize=60;
    }
    else if(score>200){
        virusSize=60;
    }

    /*append new viruses to the list if the virus array is about to 
    running out of virus*/
    if(viruses.length<10){
        makeFiveNewViruses()};
    if(sushiArray.length<2){
        makeNewSushi()};
    //console.log(viruses.length)

    //check collision for every virus in the array
    //check collision only when the timeCounter%10==0
    //we can't check collision at every frame otherwise life will be reducted mulpital times for one collision
    for(var i=0;i<viruses.length;i++){
        if(timer%10==0){
            checkCollision(ninja,viruses[i]);
        }

        //remove the virus that goes off the screen 
        if(viruses[i].x<=-20){
            viruses.splice(viruses[i],1);
            score+=1;
            
        } 



    }

    for(var i=0;i<clouds.length;i++){
        checkCloudCollision(ninja,clouds[i]);
    
    }
    for(var i=0;i<sushiArray.length;i++){
        checkSushiCollision(ninja,sushiArray[i]);
    
    }
    updateAndDisplayClouds();
    removeCloudsThatHaveSlippedOutOfView();
    addNewCloudsWithSomeRandomProbability();
    //constantly check if the game is over
    //gameover condition: life is used up

    checkGameOver(); 

    
  
    
}

//if gameover, clear the canvas, stop the loop
function checkGameOver(){
    if(life==0){
        background(220);
        fill('red');
        text("Game Over!",250,100);
        noLoop();
        game.stop();
    }
}

function drawCircles(){
    noStroke();
    translate(307,85);
    for(var i = 0; i < 12; i++){
        xvalues[i]=r*cos(radians(startAngles[i]+theta));
        yvalues[i]=r*sin(radians(startAngles[i]+theta));
        fill(circleColor[i]);
        circle(xvalues[i],yvalues[i],10);
        theta-=0.05;
    }
}

//ninja consructor
function makeNinja(sx,sy,ninjaImage,ninjaSize){
    var ninja={x: sx, y: sy, sz:ninjaSize,vy: 0, gravity: 1.9, img:ninjaImage, show: ninjaDraw, jump:ninjaJump,
        move:ninjaMove

    }
    return ninja
}


//virus constructor
function makeVirus(sx,sy,virusSize,virusImage){
    var virus={x: sx, y: sy, sz:virusSize, vx:-7, img:virusImage, show: virusDraw, 
        move:virusMove

    }
    return virus
}

//sushi constructor
function makeSushi(sx,sy,sushiImg,sushiSize){
    var ss={x: sx, y: sy, sz:sushiSize, vx:-1, img:sushiImg, show: sushiDraw, 
        move:sushiMove

    }
    return ss
}

//make new viruses when needed
function makeFiveNewViruses(){
    for(var i=0;i<5;i++){
        viruses.push(makeVirus(viruses[viruses.length-1].x+random(120,800),height-50,virusSize,random(virusImages)));
    }
}

function makeNewSushi(){
        sushiArray.push(makeSushi(sushiArray[sushiArray.length-1].x+random(width*2,width*4),random(20,190),sushiImg, sushiSize));
    
}

function ninjaDraw(){
    image(this.img,this.x,this.y,this.sz,this.sz);
}

function virusDraw(){
    image(this.img,this.x,this.y,this.sz,this.sz);
}

function sushiDraw(){
    image(this.img,this.x,this.y,this.sz,this.sz);
}

function ninjaJump(){
    //prevents the ninja from sticking at the top (if player keeps pressing space)
    if(this.y>=height-100){
        this.vy=-25;
    }

    

}


//implement gravity
//use constrain to prevent the ninja from going offscreen
function ninjaMove(){
    this.y+=this.vy;
    this.vy+=this.gravity;
    this.y=constrain(this.y,0,height-this.sz);
 
  

  
    
}


//collision detection
function checkCollisionAandB(A,B){
    if(A.x < B.x + B.sz &
        A.x + A.sz > B.x &&
        A.y < B.y + B.sz &&
        A.y + A.sz > B.y){
            return true
    }
    

}
function checkCollision(ninja,virus){
    if(checkCollisionAandB(ninja,virus)){
            life-=1
    }
    

}

//masks give players life
function checkCloudCollision(ninja,cloud){
    if(checkCollisionAandB(ninja,cloud)){
            mask.play();
            clouds.splice(cloud,1);
            life+=1
    }
    

}

//sushi give players scores
function checkSushiCollision(ninja,sushi){
    if(checkCollisionAandB(ninja,sushi)){
        sushiSound.play();
        sushiArray.splice(sushi,1);
        score+=20; 
    }
    

}




function virusMove(){
    this.x+=this.vx;
  

    
}

function sushiMove(){
    this.x+=this.vx;
  

    
}

//ninja jumps when player presses the space
function keyPressed(){
    if(key==' '){
        ninja.jump();
        jump.play();
    }
}

function updateAndDisplayClouds(){
    // Update the clouds(masks)' positions, and display them.
    for (var i = 0; i < clouds.length; i++){
        clouds[i].move();
        clouds[i].display();
    }
}    

function removeCloudsThatHaveSlippedOutOfView(){
    var cloudsToKeep = [];
    for (var i = 0; i < clouds.length; i++){
        if (clouds[i].x + clouds[i].sz > 0) {
            cloudsToKeep.push(clouds[i]);
        }
    }
    clouds = cloudsToKeep; 
}

function addNewCloudsWithSomeRandomProbability() {
    var newCloudLikelihood = 0.01; 
    if (random(0,5) < newCloudLikelihood) {
        clouds.push(makeCloud(width));
    }
}

function makeCloud(birthLocationX) {
    var cld = {x: birthLocationX,
                cloudImage:cloudImg,
                y:random(10,100),
                speed: -0.5,
                sz:random(25,60),
                move: cloudMove,
                display: cloudDisplay}
    return cld;
};

function cloudMove() {
    this.x += this.speed;
}
function cloudDisplay() {
    image(this.cloudImage,this.x,this.y,this.sz,this.sz*0.5);

}





Project – 11

Cars
//Shaun Murray, shaunmur
//Section B

var cars = [];


function setup() {
    createCanvas(300, 200); 
    
    // create an initial collection of cars
    for (var i = 0; i < 15; i++){
        var rx = random(width);
        cars[i] = makeCars(rx);
    }
    frameRate(12);
}


function draw() {
    background(220);
	noStroke();
	fill('Orange');
    rect(0, 0, 300, 120);
    fill('Yellow');
    circle(40, 110, 40);
    fill(248, 240, 164);
    rect(0, 120, 300, 140);
	line(20, 200, 100, 65);
	line(280, 200, 200, 65);
    displayHorizon();
    push();
    strokeWeight(8);
	stroke(0, 150, 0);
	line(width-75, height-60, width-75, height-73);
	strokeWeight(4);
	line(width-82, height-67, width-75, height-67);
	line(width-82, height-67, width-82, height-70);
	pop();
    updateAndDisplayCars();
    removeCarsThatHaveSlippedOutOfView();
    addNewCarsWithSomeRandomProbability(); 
}


function updateAndDisplayCars(){
    // Update the car's positions, and display them.
    for (var i = 0; i < cars.length; i++){
        cars[i].move();
        cars[i].display();
    }
}


function removeCarsThatHaveSlippedOutOfView(){
    var carsToKeep = [];
    for (var i = 0; i < cars.length; i++){
        if (cars[i].x + cars[i].breadth > 0) {
            carsToKeep.push(cars[i]);
        }
    }
    cars = carsToKeep; // remember the surviving cars
}


function addNewCarsWithSomeRandomProbability() {
    // With a very tiny probability, add a new car to the end.
    var newCarLikelihood = 0.03; 
    if (random(0,1) < newCarLikelihood) {
        cars.push(makeCars(width));
    }
}


// method to update position of car every frame
function carsMove() {
    this.x += this.speed;
}
    

// draw the car and some wheels
function carDisplay() {
    var floorHeight = 20;
    var bHeight = this.nFloors * floorHeight; 
    fill(255); 
    stroke(0); 
    push();
    translate(this.x, height - floor(random(30, 40)));
    //rect(0, -bHeight, this.breadth, bHeight);
    fill(255);
	circle(6, 6, 4);//Wheels
	circle(-6, 6, 4);
	fill('Red');
	beginShape();//body
	vertex(-9, -5);
	vertex(-10, 5);
	vertex(10, 5);
	vertex(9, -5);
	endShape(CLOSE);
	fill('cyan');
	rect(-9, -4, 4, 4);//windshield
    stroke(200); 
    pop();
}


function makeCars(birthLocationX) {
    var crs = {x: birthLocationX,
                breadth: 50,
                speed: -1.0,
                nFloors: round(random(1,1)),
                move: carsMove,
                display: carDisplay}
    return crs;
}


function displayHorizon(){
    stroke(0);
    fill(115,69,19);
    rect(0,height-50, 300, 30)
    line (0,height-50, width, height-50); 
    line (0,height-20, width, height-20);
}

function car() {
	push();
	translate(x, y);
	fill(255);
	circle(6, 6, 4);//Wheels
	circle(-6, 6, 4);
	fill('Red');
	beginShape();//body
	vertex(-9, -5);
	vertex(-10, 5);
	vertex(10, 5);
	vertex(9, -5);
	endShape(CLOSE);
	fill('cyan');
	rect(-9, -4, 4, 4);//windshield
	pop();
}

Cars on a bumpy desert road.

LO-11

Lorna Barnshaw is/was (does not seem updated) a student at the Winchester School of Art. She works as part of a student run art curating team. The goal of this team is to create an accessible outlet for students to display their art. Lorna posted a project on Behance called Reality Reduction. I find this project fascinating. The project is a mixture between digital media and computation. The project takes images of faces and maps them on to a face like model, only the models are misshapen purposely. This creates a somewhat disturbing image though Lorna takes the project a step further. As the face model spins around, the polygon count is suddenly and drastically reduced, giving the model a bizarre glitch-like appearance. I very much enjoy the ingenuity and vision shown through the art project. I am interested to see more of Lorna’s works!

Lorna Barnshaw

Project-11

sketch

I created this landscape story about skiing. There was mountain scrolling in the background and decoration banners saying that this is a skiing resort. The trees are scrolling to the left to create the effect that the skier is moving to the right. There are four types of trees and they all appear randomly. The size of the tree is also randomly decided. There are balloons floating in the sky and yellow stars shining in the background to make this scene more interesting. The balloons appear at random height from mid-air to the highest sky in the program.

//Heying Wang 
//Section B
var skier;
var birdImg;
var treeTypes=[]
var trees=[];
var birds=[];

//use noise to draw terrain
var noiseParam=0;
var noiseStep=0.05;
var values=[];


function preload(){
    //three types of Christmas tree
    var tree2 = loadImage("https://i.imgur.com/NJBdtua.png");
    treeTypes.push(tree2);
    var tree3=  loadImage("https://i.imgur.com/CU8yOAQ.png");
    treeTypes.push(tree3);
    var tree4=  loadImage("https://i.imgur.com/5Nyq5gE.png");
    treeTypes.push(tree4);
    var tree5=  loadImage("https://i.imgur.com/gCqcv9f.png");
    treeTypes.push(tree5);
    skier=loadImage("https://i.imgur.com/zbJ0fyD.png");
    birdImg=loadImage("https://i.imgur.com/H0cfnnj.png");
    

  }
function setup() {
    createCanvas(480, 300);
    for (var i = 0; i < 10; i++){
        var rx = random(width*3);
        trees[i] = makeTree(rx);
    }

    for(i=0;i<=width/12;i++){
        var n=noise(noiseParam);
        var value=map(n,0,1,0,height);
        values.push(value);
        noiseParam+=noiseStep;
    }
    for (var i = 0; i < 3; i++){
        var rx = random(width);
        birds[i] = makeBird(rx);
    }
    frameRate(13);
 
    
}

function draw() {
    background(220,220,250);
    imageMode(CENTER);

    
    fill(90,20,60);
    rect(0,0, width, height-150); 
    values.shift();
    var newRandom=map(noise(noiseParam),0,1,0,height);
    values.push(newRandom);
    noiseParam += noiseStep;
    drawTerrain();
    //draw the banner and pillers
    fill('grey');
    rect(0,50,30,height-50);
    rect(width-30,50,30,height-50);
    fill(140,40,40);
    rect(30,50,width-60,20);
    fill(255);
    text('2020 ski season',width/2-20,62);
    fill(20,30,70);
    rect(0,height-50, width, height-150); 


    updateAndDisplaytrees();
    removeTreesThatHaveSlippedOutOfView();
    addNewTreesWithSomeRandomProbability(); 

    updateAndDisplaybirds();
    removeBirdsThatHaveSlippedOutOfView();
    addNewBirdsWithSomeRandomProbability(); 
    //draw skier
    var skierX=240+random(-0.5,0.5);
    image(skier,skierX,240,100,100);

    noStroke();
    fill('yellow');
    for(var i=0;i<10;i++){
        circle(random(width),random(height-100),2,2);
    }

}

function updateAndDisplaytrees(){
    // Update the trees' positions, and display them.
    for (var i = 0; i < trees.length; i++){
        trees[i].move();
        trees[i].display();
    }
}  
function updateAndDisplaybirds(){
    // Update the birds' positions, and display them.
    for (var i = 0; i < birds.length; i++){
        birds[i].move();
        birds[i].display();
    }
}      

function removeTreesThatHaveSlippedOutOfView(){
    var treesToKeep = [];
    for (var i = 0; i < trees.length; i++){
        if (trees[i].x + trees[i].breadth > 0) {
            treesToKeep.push(trees[i]);
        }
    }
    trees = treesToKeep; 
}
function removeBirdsThatHaveSlippedOutOfView(){
    var birdsToKeep = [];
    for (var i = 0; i < birds.length; i++){
        if (birds[i].x + birds[i].size > 0) {
            birdsToKeep.push(birds[i]);
        }
    }
    birds = birdsToKeep; 
}


function addNewTreesWithSomeRandomProbability() {
    var newTreeLikelihood = 0.007; 
    if (random(0,1) < newTreeLikelihood) {
        trees.push(makeTree(width));
    }
}

function addNewBirdsWithSomeRandomProbability() {
    var newBirdLikelihood = 0.02; 
    if (random(0,1) < newBirdLikelihood) {
        birds.push(makeBird(width));
    }
}

function makeTree(birthLocationX) {
    var tre = {x: birthLocationX,
                breadth: random(60,70),
                speed: -2,
                treeType: random(treeTypes),
                move: treeMove,
                display: treeDisplay}
    return tre;
};
function makeBird(birthLocationX) {
    var bir = {x: birthLocationX,
                birdImage:birdImg,
                y:random(30,200),
                speed: -2,
                size:random(15,60),
                move: birdMove,
                display: birdDisplay}
    return bir;
};

function treeMove() {
    this.x += this.speed;
}
function treeDisplay() {
   image(this.treeType,this.x,215,this.breadth,this.breadth*1.4);

}
function birdMove() {
    this.x += this.speed;
}
function birdDisplay() {
    image(this.birdImage,this.x,this.y,this.size,this.size*1.2);

}



function drawTerrain(){
    //draw the terrain using begin shape and end shape
    noStroke();
    fill('white');
    beginShape();
    vertex(0,height);
    vertex(0,height);
    for(i=0;i<=width;i+=12){
        curveVertex(i,values[i/12]);

    }
    vertex(width,height);
    vertex(width,height);
    endShape(CLOSE);}

Looking Outwards-11

Heying Wang Section B

Caroline Sinders, Feminist Data Set (2017)

Caroline Sinders is an artist interested in machine-learning and interdisciplinary areas. She holds a Masters from New York University’s Interactive Telecommunications Program. She is also the founder of Convocation Design + Research, an agency focusing on the intersections of machine learning, user research, designing for public good, and solving difficult communication problems. I chose to look at Sinders because many of her works express feminist views, political ideology, and social justice. Her works show an interesting combination of technology, fine arts, and service design. Sinders has been using machine learning a lot in her art creations.

The project that interests me is called Feminist Data Set (2017). It interrogates the AI process including data collection, data labeling, data training, etc. The project is a response to the problem of data harvesting. I think it’s a thought-provoking work that has great importance because these days people’s data are collected easily by large technological companies.The project is a social justice art practice that uses data creation as a protest. The artists’ intentions are uniquely presented. I think it’s creative to make a data-set about political ideology.

Project-11-Landscape

I choose to do a picture I took in Pakistan so I created the images in Illustrator and then created variation in the landscape. and ultimately wanted variation of falling bananas and cows in the distance.

Picture I took in Pakistan.
graanak-11
//Graana Khan 
//Section B

var noiseParam = 0;
var noiseStep = 0.05;
var weeds = []; 
var bananaGuy;
var bananas = [];
var cows = [];

function preload(){
	bananaGuy = loadImage("https://i.imgur.com/QlEAbwn.png");
	bananas[0] = "https://i.imgur.com/DGbCivK.png";
	bananas[1] = "https://i.imgur.com/kYS7JBv.png";
	bananas[2] = "https://i.imgur.com/oLWOnSw.png";
	cows[0] = "https://i.imgur.com/DbRWV09.png";
	cows[1] = "https://i.imgur.com/IDXjr5m.png";
	cows[2] = "https://i.imgur.com/rHLRVkb.png";

	for(var i=0; i < bananas.length; i++){
		bananas[i] = loadImage(bananas[i]);
	}

	for(var i=0; i < cows.length; i++){
		cows[i] = loadImage(cows[i]);
	}
}

function setup() {
    createCanvas(480, 300);
    background(220);
    frameRate(10);

    strokeWeight(5);

    //initializing the noise and array
    for(var i=0; i <= 100; i++){
    	var n = noise(noiseParam);
    	var value = map(n, 0, 1, 100, height);
    	weeds.push(value);
    	noiseParam += noiseStep; 
    }

}

function draw() {
	background(232, 208, 156);

//terrain moving in the background
	weeds.shift();
	var n = noise(noiseParam);
	var value = map(n, 0, 1, 100, height);
	weeds.push(value);
	noiseParam += noiseStep; 

	stroke(135, 119, 76);
	fill(135, 119, 76);
	beginShape();
	curveVertex(0, height);
	curveVertex(0, height);
	for(var i=0; i < 100; i++){
		vertex(i*30, weeds[i]);
	}
	vertex(width, height);
	vertex(width, height);
	endShape();
//dirt road
	noStroke();
	fill(96, 78, 41);
	rect(0, 229, 480, 71);

//banana truck 
	image(bananaGuy, 0, 0, 480, 300);

	image(bananas[2], 260, 260);
	scale(0.5);
	image(cows[0], 120, 370);

}

Project 11 – Generative Landscape

sketch
var houses = [];
var sky;

function preload() {
    sky = loadImage("https://i.imgur.com/FaHkkqz.jpg");
}

function setup() {
    createCanvas(480, 435);
    background(220);
    for (var i = 0; i < 10; i ++) {
        houses[i] = makeHouse(i * 0.5);
    }
    frameRate(10);
}

function draw() {
    background(0, 30, 140);
    image(sky, 0, -100, 480, 600);
    moon();
    updateAndDisplayHouses();
    removeHouses();
    addNewHouses();
    man();
    gondola();
}

function updateAndDisplayHouses() {
    for (var i = 0; i < houses.length; i++) {
        houses[i].move();
        houses[i].display();
    }
}

function removeHouses() {
    var housesToKeep = [];
    for (var i = 0; i < houses.length; i++) {
        if (houses[i].x + houses[i].breadth > 0) {
            housesToKeep.push(houses[i]);
        }
    }
    houses = housesToKeep;
}

function addNewHouses() {
    //probability
    var newHouseLikelihood = 5;
    if (random(0, 200) < newHouseLikelihood) {
        houses.push(makeHouse(width));
    }
}

function houseMove() {
    this.x += this.speed;
}

function houseDisplay() {
    //draws the houses
    var floorHeight = 10;
    var bHeight = this.nFloors * floorHeight;
    fill(100);
    stroke(0);
    strokeWeight(1);
    push();
    translate(this.x, height);
    rect(0, -bHeight, this.breadth, bHeight);
    //windows
    for (var i = 0; i < this.nFloors; i++) {
        for (var j = 0; j < this.breadth / 20; j++) {
            fill(255);
            rect(j * 15 + 10, -(i * floorHeight), 5, 5);
        }
    }
    pop();
}

function makeHouse(birthLocationX) {
    var hse = {x: birthLocationX,
                breadth: 50,
                speed: -1.0,
                nFloors: round(random(3,8)),
                move: houseMove,
                display: houseDisplay}
    return hse;
}

function moon() {
    fill(255, 255, 181);
    noStroke();
    circle(240, 400, 300);
}

function gondola() {
    noStroke();
    fill(0);
    rect(150, 420, 200, 20);
    ellipse(145, 425, 40, 15);
    ellipse(355, 425, 40, 15);
    noFill();
    stroke(0);
    strokeWeight(10);
    arc(250, 410, 250, 30, radians(0), radians(180));
    arc(150, 415, 50, 40, radians(90), radians(180));
    arc(350, 415, 50, 40, radians(0), radians(90));
    //oar
    stroke(0);
    strokeWeight(4);
    line(180, 340, 155, 438);
}

function man() {
    fill(0);
    noStroke();
    circle(150, 348, 20);
    quad(145, 340, 145, 390, 160, 390, 150, 340);
    rect(145, 390, 10, 30);
    stroke(0);
    strokeWeight(4);
    line(155, 370, 170, 370);
    line(153, 373, 167, 377);
}

Man paddles through the Hudson at night, admiring the city.