Steven Fei-Project 11-Generative Landscape

sketch

//Steven Fei
//zfei@andrew.cmu.edu
//project 11
//section-A
var stars = [];
function setup() {
    createCanvas(480, 480);
    frameRate(8);
    //set the initial display of the stars
    for(var i = 0; i<8; i++){
        var sx = random(width);
        var sy = random(50, height/3);
        stars[i] = makeStars(sx, sy);
    }
    
}



function draw() {
    background("black");
    //create the terrain in the far back of the canvas
    var terrain3 = terrain(30, 2, height/5, height * 3/4, 3);
    //create the terrain in the middle of the canvas
    var terrain2 = terrain(80, 2, height/3, height * 3/4, 2);
    //create the terrain in the front of the canvas
    var terrain1 = terrain("white", 2, height/2, height * 3/4, 1);
    //create the blue lake at the bottom of the canvas
    noStroke();
    fill(0,33,41);
    rect(0, height * 4/5, width, height);
    //create trees
    for (var x = 0; x < width; x+=5){
        var orange = random(80,150);
        stroke(240, orange, 80);//define the color of the tree to draw
        strokeWeight(1.2);
        push();
        translate(x * random(5,10), height * 4/5);
        drawTree(0, random(5,15), int(random(3,6)));//calling the function to draw the tree
        pop();
    }
    //update star by showing the stars and the moving positions of the stars
    updateStar();
    //only keep the stars that are still on the canvas
    removeStar();
    //add new stars under a certain probability
    addStars();
}
//showing the star positions
function updateStar(){
    for (var i = 0; i<stars.length; i++){
        stars[i].move();
        stars[i].display();
    }
}
//only keep the stars on the canvas
function removeStar(){
    var starKeep = [];
    for ( var i = 0; i < stars.length; i++){
        if(stars[i].x > 0){
            starKeep.push(stars[i]);
        }
    }
    stars = starKeep;
}
//add more stars by chance
function addStars(){
    var starProbability = 0.01;
    if(random(0,1) < starProbability){
        stars.push(makeStars(width,random(50,height/3)));
    }
}
//defining the moving speed of the star
function starMove(){
    this.x += this.speed;
}
//displaying the star by drawing the circle
function starDisplay(){
    fill("white");
    noStroke();
    push();
    translate(this.x, this.y);
    circle(0,0,this.size);
    pop();
}
//main function to make the star
function makeStars(birthX, birthY){
    var str = { x: birthX,
                y: birthY,
                speed: -1.5,
                size: random(5,15),
                move: starMove,
                display: starDisplay};
    return str;
                
}
//making the terrain
var terrainSpeed = 0.0005;
var terrainDetail = 0.005;
function terrain(color,strokeweight,min,max,noiseseed){
    var verticesX = [];//array to append values for x coordinates
    var verticesY = [];//array to append values for y coordinates
    noiseSeed(noiseseed);//decide the pseudo random number seed
    stroke(color);//the color to choose to draw the terrain
    strokeWeight(strokeweight);//the strokeweight to choose to draw
    noFill();
    beginShape();
    for ( var x = 0; x < width; x++){
        var t = (x * terrainDetail) + (millis() * terrainSpeed);
        var y = map(noise(t), 0, 1, min, max);
        vertex(x,y);//generating the terrain points 
        verticesX.push(x);
        verticesY.push(y);
        if(verticesX.length > width){
            verticesX.shift();
            verticesY.shift();
        }
    }
    for ( var j = 0; j < verticesX.length; j++){
        line(verticesX[j], verticesY[j], verticesX[j],height);//add vertical coloring to the terrain
    }
    endShape();  
}
//function to draw trees by defining depth(number of branches), len(branch length), seed(upper limit of the branch counts)
function drawTree(depth, len, seed){
    if(depth < seed){
        rotate(radians(-10));
        drawBranch(depth,len, seed);
        rotate(radians(20));
        drawBranch(depth,len, seed);
    }
}
function drawBranch(depth, len, seed){
    line(0,0,0,-len);
    push();
    translate(0,-len);
    drawTree(depth + 1, len, seed);
    pop();
}

For this project, I was intended to create a serene atmosphere by the lake. The mountains are majorly created in 3 layers with different shades to represent a sense of depth and distance. Symbolic maple trees were drawn in different saturations of orange and different sizes and branch counts to have a “realistic” impression of the diverse range of the trees. The circular stars are moving in the upper part of the canvas to strengthen the sense of moving. By setting different moving speed of those different objects, I was aiming to deepen a spatial feeling in the visual hierarchy. The maple trees were moving fastest because they are relatively in the very front of the canvas, while the mountains are constantly moving slower, and the stars are the slowest. The project gives me some chances to make different objects and functions and use different strategies to fulfill those elements through building a connection between the draw function and the other specific functions I make for the elements.

Inspiration to draw a starry night by the lake

Ankitha Vasudev – Project 11 – Landscape

sketch

// Ankitha Vasudev
// Section B
// ankithav@andrew.cmu.edu
// Project-11

// global variables
var birds = []; // bird objects

var terrainSpeed1 = 0.0005; // back mountains speed
var terrainDetail1 = 0.015; // back mountains detail
var terrainSpeed2 = 0.001;  // front mountains speed
var terrainDetail2 = 0.008; // front mountains detail

function setup() {
	createCanvas(450, 400);

	// create an initial collection of birds
	for (var i = 0; i<10; i++) {
		var rx = random(width);
		birds[i] = makeBirds(rx);
	}

    frameRate(10);
}

function draw() {
    background(80);
    
    // window arc frame 
    fill(230);
    arc(width/2, 400, width*2, 750, PI, 0);

    // landscape elements
    sun();
    backMountains();
    carWindowandRoad();
    frontMountains();
    mountainreflection();

    // displaying birds 
    updateAndDisplayBirds();
    removeOldBirds();
    addNewBirds();

    // vertical window frame line
	stroke(0);
	strokeWeight(7);
	line(75, 50, 75, height);
}

function carWindowandRoad() {

    // window frame
	stroke(0);
	strokeWeight(7);
	noFill();
	arc(width/2, 400, width*2, 750, PI, 0);

	// water
	noStroke();
	fill(230);
	rect(0, 340, width, 100);

	// road
	stroke(255);
	strokeWeight(2);
	fill(100);
	rect(-10, 380, width+20, 70);

    // bottom window frame
    noStroke();
    fill(0);
	rect(0, 393, width, height);
}

function backMountains() {
	// large mountains in the back 
    stroke(215);
    beginShape();
	for(var x=0; x<=width; x++) {
		var t = (x * terrainDetail1) + (millis() * terrainSpeed1);
		var y = map(noise(t), 0, 1, 100, 350);
		line(x, y, x, 380);
	}
	endShape();
}

function frontMountains() {
	// smaller mountains in the front
	stroke(150);
    beginShape();
	for(var x=0; x<=width; x++) {
		var t = (x * terrainDetail2) + (millis() * terrainSpeed2);
		var y = map(noise(t), 0, 2, 300, 200);
		line(x, y, x, 340);
	}
	endShape();
}

function mountainreflection() {
	// reflection of small mountains in the water
    stroke(200);
    beginShape();
	for(var x=0; x<=width; x++) {
		var t = (x * terrainDetail2) + (millis() * terrainSpeed2);
		var y = map(noise(t), 0, 5, 120, 250);
	    line(x, y+220, x, 340);
	}
	endShape();
}

function sun() {
	//sun 
	noStroke();
	fill(238);
	ellipse(370,100, 60);
	fill(247);
	ellipse(370, 100, 55);
	fill(255);
	ellipse(370, 100, 50);
}

function updateAndDisplayBirds() {
	// display and move birds
    for (var i=0; i<birds.length; i++) {
    	birds[i].move();
    	birds[i].display();
    }
}

function removeOldBirds() {
	// remove old birds off canvas
	var birdsToKeep = [];
	for (var i=0; i<birds.length; i++) {
		if (birds[i].x + birds[i].breadth > 0) {
			birdsToKeep.push(birds[i]);
		}
	}
	birds = birdsToKeep;
}

function addNewBirds() {
	// add new birds with a probability of 0.05
	var newBirds = 0.05;
	if (random(0,1) < newBirds) {
		birds.push(makeBirds(width));
	}
}

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

function displayBirds() {
	// code to draw each bird
	noFill();
	stroke(this.col);
	strokeWeight(0.8);
	arc(this.x, this.y, this.width, this.height, PI, TWO_PI);
	arc(this.x+this.width, this.y, this.width, this.height, PI, TWO_PI);
}

function makeBirds(birthLocationX) {
	// randomization of birds
	var birdy = {x: birthLocationX,
		y: random(140, 230),
		col: random(30,100),
		breadth: 50,
        speed: random(-3,-6),
        width: random(3,8),
        height: random(2,4),
        move: moveBirds,
		display: displayBirds
	}
    return birdy;
}

For this project I created a generative landscape of a view out a car window. I wanted to create a strong sense of foreground vs background and did this by including many elements: mountains in the back and front, water with the mountain reflections and a thin strip of the road. I used birds as my objects and randomized the width, height and color. I also used this project as an opportunity to play with a monotone color scheme (since all my previous project use a lot of color). Overall, it was fun and I’m much more confident about using objects. 

Initial ideas for my project

Chelsea Fan-Project 11-Landscape

Landscape

/* Chelsea Fan
Section 1B
chelseaf@andrew.cmu.edu
Project-11
*/
//important variables
var fish = [];
var star = [];

function setup() {
    createCanvas(480, 480);
    frameRate(20);
    //initial collection of fish
    for (i = 0; i < 30; i++) {
        var fishx = random(width);
        var fishy = random(300, height);
        fish[i] = makeFish(fishx, fishy);
    }
    //initial collection of stars
    for (i = 0; i < 10; i++) {
        var starx = random(width);
        var stary = random(0, 100);
        star[i] = makeStar(starx, stary);
    }
}

function draw() {
    //black background
    background(0);
    //draw mountains, water, bed, fish, stars, and moon
    drawMountains();
    drawWater();
    drawBed();
    fishies();
    stars();
    drawMoon();
}

function drawBed() {
    stroke(0); //black outline
    fill(255, 254, 242); //bed color
    rect((width/2)-30, (height/2)-10, 150, 40); //bed shape
    fill(255); //pillow color
    ellipse(width/2+105, height/2-14, 30, 10); //pillow shape
    fill(255, 243, 222); //head color
    ellipse(width/2+100, height/2-25, 20, 20); //head shape
    noStroke(); //no outline for neck
    ellipse(width/2+83, height/2-20, 20, 5); //neck shape
    stroke(0); //black outline
    fill(203, 202, 204); //blanket color
    ellipse(width/2+30, height/2-10, 120, 40); //blanket shape
}

function drawWater() {
    fill(66, 112, 128); //blue water color
    rect(0, height/2, width, height); //fill bottom half of canvas
}

function drawFish() {
    noStroke(); //no outline
    fill(255, 160, 122); //orange fish color
    push();
    translate(this.x1, this.y1); //locate fish at x1, y1
    ellipse(10, 10, 10, 5); //fish body
    triangle(10, 10, 5, 5, 5, 15); //fish tail
    pop();
}

function makeFish(xlocation, ylocation) {
    var makeF = {x1: xlocation, 
                y1: ylocation, 
                fishx: random(0, width), 
                fishy: random(300, height),
                speed: -3.0,
                move: moveFish,
                draw: drawFish}
    return makeF;
}

function moveFish() {
    this.x1 += this.speed; //speed of fish moving
    if (this.x1<=-10) { //restart fish at width after it disappears on left
        this.x1 += width;
    }
}

function fishies() {
    for(i=0; i<fish.length; i++) {
        fish[i].move();
        fish[i].draw();
    }
}

function drawStar() {
    noStroke();
    fill(255, 251, 0); //yellow color
    push();
    translate(this.x2, this.y2); //draw stars at x2, y2
    ellipse(10, 10, 5, 5); //star shape
    pop();
}

function makeStar(xlocation, ylocation) {
    var makeS = {x2: xlocation, 
                y2: ylocation, 
                starx: random(0, width), 
                stary: random(0, 100),
                speed: -3.0,
                move: moveStar,
                draw: drawStar}
    return makeS;
}

function moveStar() {
    this.x2 += this.speed; //speed of stars moving
    if (this.x2<=-10) { //restart stars on right if it leaves canvas
        this.x2 += width;
    }
}

function stars() {
    for(i=0; i<star.length; i++) {
        star[i].move();
        star[i].draw();
    }
}

function drawMoon(){
    fill(255, 253, 184); //yellow moon color
    ellipse(400, 50, 50, 50); //moon shape
}

function drawMountains(){
    noStroke();
    fill(43, 43, 36); //dark gray mountain color
    beginShape(); 
    for (i=0; i<width; i++) {
        var mountainSpeed = .0007; //speed of mountains moving
        var mountainDetail = 0.02; //smoothness of mountains
        var t = (i * mountainDetail) + (millis() * mountainSpeed);
        //mountain y coord
        var y = map(noise(t), 0, 1.8, height/8, height);
        //keep drawing mountain
        vertex(i, y);
    }
    //height constriant of mountains
    vertex(width, height);
    //restart mountains at left side 
    vertex(0, height);
    endShape();
}

This process took me a long time. I spent a while thinking about what I wanted to draw and I decided on a Parent Trap theme with a bed floating in the ocean. The stars, moon, mountains, and fish are meant to resemble an ocean view at night. I had some difficulty making my own object, but once I got the hang of it, it was pretty fun.

My draft (Nov. 5, 2019).

Jamie Park – Project 11

sketch

//Jamie Park           jiminp@andrew.cmu.edu
//15-104          Section E        Project 11

var xCirc = 100;
var yCirc = 120;
var moonX = 270;
var airplaneSound;
var airplanePic;


function preload(){
    var airplaneURL = "https://i.imgur.com/4Vw2nUw.png"
   airplanePic = loadImage(airplaneURL);

   airplaneSound = loadSound("https://courses.ideate.cmu.edu/15-104/f2019/wp-content/uploads/2019/11/325845__daveshu88__airplane-inside-ambient-cessna-414-condenser.mp3");
}

function setup(){
    createCanvas(450, 450);
    frameRate(9.5);
    useSound();
}

function soundSetup(){
    airplaneSound.setVolume(0.2);
    airplaneSound.play();
    airplaneSound.loop();
}

function draw(){
    background('#1b2c4d');
    stars();
    moon();
    cloud();
    canyons();
    canyons2();
    canyons3();
    image(airplanePic, 0, 0);
}

function canyons(){

    var terrainSpeed = 0.0005;
    var terrainDetail = 0.005;

    noStroke();
    fill('#c96e57');
    beginShape();
    for(var x = 0; x < width; x++){
        var t = (x * terrainDetail) + (millis() * terrainSpeed);
        var y = map(noise(t), 0, 0.85, 0, height);
        vertex(x, y);
    }
    vertex(width, height);
    vertex(0, height);
    endShape();
}

function canyons2(){

    var terrainSpeed = 0.0005;
    var terrainDetail = 0.0059;

    noStroke();
    fill('#913e29');
    beginShape();
    for(var x = 0; x < width; x++){
        var t = (x * terrainDetail) + (millis() * terrainSpeed);
        var y = map(noise(t), 0, 0.65, 0, height - 5);
        vertex(x, y);
    }
    vertex(width, height);
    vertex(0, height);
    endShape();
}

function canyons3(){

    var terrainSpeed = 0.0005;
    var terrainDetail = 0.004;

    noStroke();
    fill('#703223');
    beginShape();
    for(var x = 0; x < width; x++){
        var t = (x * terrainDetail) + (millis() * terrainSpeed);
        var y = map(noise(t), 0, 0.5, 0, height);
        vertex(x, y);
    }
    vertex(width, height);
    vertex(0, height);
    endShape();
}

function cloud(){
    noStroke();
    fill('#2f446b');

    ellipse(xCirc, yCirc + 20, 40, 40);
    ellipse(xCirc + 30, yCirc + 10, 60, 60);
    ellipse(xCirc + 60, yCirc, 50, 50);
    ellipse(xCirc + 70, yCirc + 15, 70, 60);
    ellipse(xCirc + 100, yCirc + 10, 60, 60);
    ellipse(xCirc + 130, yCirc + 10, 45, 45);
    xCirc = xCirc - 5;

    if (xCirc === -100){
        xCirc = width;
    }
}

function stars(){
    starX = random(width);
    starY = random(height / 2);

    for (var i = 0; i < 50; i++){
        strokeWeight(2);
        stroke("#e8e8cc");
        point(starX, starY);
    }
}

function moon(){
    noStroke();
    fill("#f0e3cc");
    ellipse(moonX, 180, 100, 100);
    fill("#edd4a8");
    ellipse(moonX, 180, 70, 70);

    moonX = moonX - 0.15;

    if (moonX === 0){
        moonX = 400;
    }
}

I approached this project by brainstorming transportations with windows and ended up landing upon airplanes. The code I have created is a visual of red canyons beyond an airplane window. The stars sparkle at random points of the canvas, and the cloud and the moon shifts left towards the canvas. I had added airplane noise to the file to hint that this is a point of view from an airplane. I really enjoyed the process of visualizing my ideas and I feel like I am becoming more confident in coding.

Sketchbook notation of my ideas

Lanna Lang – Project 11 – Landscape

sketch

//Lanna Lang
//Section D
//lannal@andrew.cmu.edu
//Project 11 - Landscape

//variables for the gradients;
var yAxis = 1;
var c1, c2, c3, c4, c5; //background colors

//variables to draw the clouds
var cloudX = [500, 700, 1200];
var cloudY = [150, 120, 190];
var cloudDist = 5; //the distance the cloud moves

//arrays for the tree and house objects
var trees = [];
var houses = [];

function setup() {
    createCanvas(480, 480);
    frameRate(20);

    c1 = color('#9a99d3'); //background sky lavender
    c2 = color('#ff829f'); //background sky pink
    c3 = color('#f6944d'); //background sky orange
    c4 = color('#a29078'); //train color 1
    c5 = color('#f2f2f4'); //train color 2

    //create an initial collection of trees
    for (var i = 0; i < 10; i++) {
        var rtx = random(width);
        var rty = random(281, 330);
        trees[i] = makeTree(rtx, rty);
    }
    //create an initial collection of houses
    for (var i = 0; i < 10; i++) {
        var rhx = random(width);
        var rhy = random(300, 350);
        houses[i] = makeHouse(rhx, rhy);
    }
}

function draw() {
    drawBackground();
    drawClouds();
    drawLandscape();

    UandDTrees();
    removeTrees();
    addNewTrees();
    
    UandDHouses();
    removeHouses();
    addNewHouses();

    drawTrain();
}

//function to draw the background and 
//the canvas for the train
function drawBackground() {
    //rectangle around full canvas
    drawGradDGtoG(0, 0, width, height, c4, c5, yAxis);

    //draw the sky with gradients
    drawGradPtoP(35, 100, 400, 80, c1, c2, yAxis);
    drawGradPtoO(35, 181, 400, 105, c2, c3, yAxis);
}

//draw the landscape inside the train windows
function drawLandscape() {
    var mtnSpeed = 0.0005;
    var mtnDetail = 0.01;

    //draw the moutains
    stroke('#445c3c');
    for (var x = 35; x <= 435; x++) {
        var t = (x * mtnDetail) + (millis() * mtnSpeed);
        var y = map(noise(t), 0, 1, 170, 300);
        line(x, y, x, 380);
    }

    //draw the grass/horizon
    noStroke();
    fill('#798f44');
    rect(35, 281, 400, 107);
}

//draw the clouds
function drawClouds() {
    for (var i = 0; i < cloudX.length; i++) {
        cloudX[i] -= cloudDist; //the clouds move 5 pixels to the left
        //draw the 3 clouds
        noStroke();
        fill('#faa3b1');
        ellipse(cloudX[i], cloudY[i] + 10, 100, 8);
        ellipse(cloudX[i] - 24, cloudY[i] + 1, 30, 20);
        ellipse(cloudX[i] + 3, cloudY[i], 40, 22);
        ellipse(cloudX[i] - 5, cloudY[i] - 10, 40, 20);
        ellipse(cloudX[i] + 22, cloudY[i], 30, 18);
        //when the clouds reach the end of the canvas, 
        //they will reset back at the other side of the canvas
        //at a random x postion between 500 and 1300
        if (cloudX[i] < 0) {
            cloudX[i] = random(500, 1300);
        }
    }
}

//function to draw gradient from purple to pink
function drawGradPtoP(x, y, w, h, c1, c2, axis) {
    noFill();
    if (axis == yAxis) {
        for (var i = y; i <= y + h; i++) {
            var inter = map(i, y, y + h, 0, 1);
            var cPtoP = lerpColor(c1, c2, inter);
            stroke(cPtoP); 
            line(x, i, x + w, i);
        }
    }
}

//function to draw gradient from pink to orange
function drawGradPtoO (x, y, w, h, c2, c3, axis) {
    noFill();
    if (axis == yAxis) {
        for(var i = y; i <= y + h; i++) {
            var inter = map(i, y, y + h, 0 , 1);
            var cPtoO = lerpColor(c2, c3, inter);
            stroke(cPtoO);
            line(x, i, x + w, i);
        }
    }
}

//function to draw gradient from tan to light grey
function drawGradDGtoG (x, y, w, h, c4, c5, axis) {
    noFill();
    if (axis == yAxis) {
        for(var i = y; i <= y + h; i++) {
            var inter = map(i, y, y + h, 0 , 1);
            var cDGtoG = lerpColor(c4, c5, inter);
            stroke(cDGtoG);
            line(x, i, x + w, i);
        }
    }
}

//function to draw the train
function drawTrain() {
    //redraw the very left and right sides of the train
    //because of the clouds moving
    drawGradDGtoG(0, 0, 35, height, c4, c5, yAxis);
    drawGradDGtoG(435, 0, 490, height, c4, c5, yAxis);
    
    //rectangle to separate the sky gradient into two windows
    drawGradDGtoG(210, 0, 60, height, c4, c5, yAxis);
   
    //dark brown line in the middle
    noStroke();
    fill('#2e2423');
    rect(235, 0, 10, height); 

    //black rect sign under windows
    fill(0);
    rect(280, 400, 140, 20); 
    rect(50, 400, 140, 20);
    
    //dark brown window frames
    strokeWeight(2);
    stroke('#2e2423');
    noFill();
    rect(30, 85, 185, 310);
    rect(265, 85, 175, 310);

    //sign under windowa that says "Do not lean on train door"
    fill(224);
    textSize(11);
    textStyle(BOLD);
    text("Do not lean on train door", 284, 413);
    text("Do not lean on train door", 54, 413);
    
    //draw the door handles on the train doors
    stroke(193);
    fill(220);
    rect(180, 440, 35, 70);
    rect(265, 440, 35, 70);
    //draw the insides of the door handles
    fill(130);
    rect(190, 450, 15, 70);
    rect(275, 450, 15, 70);

    //draw the train handles
    for (var j = 0; j < width + 50; j += 150) {
        stroke(200);
        strokeWeight(13);
        noFill();
        line(j, 0, j, 70);
        line(j, 70, j + 33, 130);
        line(j, 70, j - 30, 130);
        line(j - 30, 130, j + 33, 130);
    }
}

//update the tree's positions, and display them
function UandDTrees() {
    for (var i = 0; i < trees.length; i++) {
        trees[i].move();
        trees[i].draw();
    }
}

//if a tree has dropped off the left edge,
//remove it from the array
function removeTrees() {
    var treesToKeep = [];
    for (var i = 0; i < trees.length; i++) {
        if (trees[i].x + trees[i].tw > 0 & 
            trees[i].y + trees[i].th > 0) {
            treesToKeep.push(trees[i]);
        }
    }
    trees = treesToKeep; //remember the surviving trees
}

//with a very tiny probability, add a new tree to the end
function addNewTrees() {
    var newTreeChance = 0.01;
    if (random(0.1) < newTreeChance) {
        trees.push(makeTree(width, random(281, 330)));
    }
}

//update position of the tree at every frame
function moveTree() {
    this.x += this.speed;
}

//draw the tree and tree trunk
function drawTree() {
    noStroke();
    fill('#c39a2b');
    push();
    translate(this.x, this.y);
    triangle(0, -this.th, 0 - this.tw / 2, 0, 
            0 + this.tw / 2, 0);
    pop();

    fill('#512a17');
    push(); 
    translate(this.x, this.y);
    rect(-3, 0, 4, 5);
    pop();
}

//this function accepts parameters and uses the values
//of those parameters to initialize fields in the tree object
function makeTree(birthLocationX, birthLocationY) {
    var mktr = {x: birthLocationX,
                y: birthLocationY,
                tw: random(5, 15),
                speed: -5.0,
                th: random(15, 30),
                move: moveTree,
                draw: drawTree}
    return mktr;
}

//update the house's positions, and display them
function UandDHouses() {
    for (var i = 0; i < houses.length; i++) {
        houses[i].move();
        houses[i].draw();
    }
}

//if a house has dropped off the left edge,
//remove it from the array
function removeHouses() {
    var housesToKeep = [];
    for (var i = 0; i < houses.length; i++) {
        if (houses[i].x2 + houses[i].hw > 0 &
            houses[i].y2 + houses[i].hh > 0) {
            housesToKeep.push(houses[i]);
        }
    }
    houses = housesToKeep; //remember the surviving houses
}

//with a very tiny probability, add a new house to the end
function addNewHouses() {
    var newHouseChance = 0.003;
    if (random(0.1) < newHouseChance) {
        houses.push(makeHouse(width, random(300, 350)));
    }
}

//update position of the tree at every frame
function moveHouse() {
    this.x2 += this.speed2;
}

//draw the house and the house roof
function drawHouse() {
    noStroke();
    fill('#e7d2a0');
    push();
    translate(this.x2, this.y2);
    rect(-10, 0, 20, 10);
    pop();

    fill('#95221b');
    push();
    translate(this.x2, this.y2);
    triangle(0, -this.hh / 2, 0 - this.hw / 2, 0, 
            0 + this.hw / 2, 0);
    pop();
}

//this function accepts parameters and uses the values
//of those parameters to initialize fields in the house object
function makeHouse(birthLocationX2, birthLocationY2) {
    var mkh = {x2: birthLocationX2,
                y2: birthLocationY2,
                hw: random(10, 40),
                speed2: -5.0,
                hh: random(10, 30),
                move: moveHouse,
                draw: drawHouse}
    return mkh;
}

When I first read this prompt, what came up to my mind immediately was creating a landscape that mimics what I see when sitting on a high-speed train. My favorite sceneries are usually what I see when I pass by complete cities in just a few hours on those trains. I had a lot of fun creating this landscape, but it was also very challenging for me. It definitely took me more than a couple of hours, but it was worth it.

My sketch

Sean Meng-Project 10-Interactive Sonic Sketch

hmeng-project-10

//Sean Meng
//hmeng@andrew.cmu.edu
//Section C
//Project-10-Interactive Sonic Sketches

var mySoundA;
var mySoundB;

function preload() {
    mySoundA = loadSound("https://courses.ideate.cmu.edu/15-104/f2019/wp-content/uploads/2019/11/mySoundA.wav");
    mySoundA.setVolume(2);

    mySoundB = loadSound("https://courses.ideate.cmu.edu/15-104/f2019/wp-content/uploads/2019/11/mySoundB.wav");
    mySoundB.setVolume(2);

    mySoundC = loadSound("https://courses.ideate.cmu.edu/15-104/f2019/wp-content/uploads/2019/11/mySoundC.wav");
    mySoundC.setVolume(2);

    mySoundD = loadSound("https://courses.ideate.cmu.edu/15-104/f2019/wp-content/uploads/2019/11/mySoundD.wav");
}

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

}
function draw() {
    var bSize = 16;

    background(255, 201, 54);

//draw the play station
    noStroke();
    fill(255);
//the body of the play station    
    rect(150, 100, 180, 270);
    
    rect(150, 90, 180, 10);
    rect(150, 370, 180, 10);
    rect(140, 100, 10, 270);
    rect(330, 100, 10, 270);
    
    ellipse(150, 100, 20, 20);
    ellipse(330, 100, 20, 20);
    ellipse(150, 370, 20, 20);
    ellipse(330, 370, 20, 20);

//the screen 
    fill(150);
    rect(160, 110, 160, 110);
    ellipse(160, 110, 16, 16);
    ellipse(320, 110, 16, 16);
    ellipse(160, 220, 16, 16);
    ellipse(320, 220, 16, 16);

    rect(160, 102, 160, 8);
    rect(160, 220, 160, 8);
    rect(152, 110, 8, 110);
    rect(320, 110, 8, 110);

    fill(30)
    rect(160, 110, 160, 110)

//Left button
    fill(0);
    rect(160, 280, 50, 10);
    rect(180, 260, 10, 50);

//Right button A
    fill(255, 0, 0);
    ellipse(290, 270, bSize);
//Right button B
    ellipse(290, 300, bSize);  
//Right button C
    ellipse(275, 285, bSize);
//Right button D
    ellipse(305, 285, bSize);    
}

function mousePressed() {
//fill the screen blue when button is clicked
    fill(138, 218, 255);
    rect(160, 110, 160, 110);

//play soundA when buttonA is clicked
    if(mouseX > 282 & mouseX < 298 && mouseY > 262 && mouseY < 278){
        mySoundA.play();
    }
//play soundB when buttonB is clicked    
    if(mouseX > 282 & mouseX < 298 && mouseY > 292 && mouseY < 308){
        mySoundB.play();
    }
//play soundC when buttonC is clicked
    if(mouseX > 267 & mouseX < 283 && mouseY > 277 && mouseY < 293){
        mySoundC.play();
    }
//play soundD when buttonD is clicked
    if(mouseX > 297 & mouseX < 313 && mouseY > 277 && mouseY < 293){
        mySoundD.play();
    }    
}

In this project, I explored the sound upload in p5js and mimicked the Nintendo Family Computer with corresponded game sound effects.

Taisei Manheim – Project 11 – Generative Landscape

sketch

//Taisei Manheim
//Section C
//tmanheim@andrew.cmu.edu
//Assignment-10

var trees = [];
var frames;

function preload() {
    //background  gradient
    backgroundImage = loadImage("https://i.imgur.com/L0VpcqE.jpg")

    //frames for person animation
    frames = [];
    frames[0] = loadImage("http://i.imgur.com/svA3cqA.png");
    frames[1] = loadImage("http://i.imgur.com/jV3FsVQ.png");
    frames[2] = loadImage("http://i.imgur.com/IgQDmRK.png");
    frames[3] = loadImage("http://i.imgur.com/kmVGuo9.png");
    frames[4] = loadImage("http://i.imgur.com/jcMNeGq.png");
    frames[5] = loadImage("http://i.imgur.com/ttJGwkt.png");
    frames[6] = loadImage("http://i.imgur.com/9tL5TRr.png");
    frames[7] = loadImage("http://i.imgur.com/IYn7mIB.png");
}

function setup() {
    createCanvas(480, 480); 
    
    // create an initial collection of trees
    for (var i = 0; i < 10; i++){
        var rx = random(width);
        trees[i] = makeTree(rx);
    }
    frameRate(10);
}

function draw() {
    image(backgroundImage, 0, 0, width * 2, height);
    mountain();
    mountain2();

    //ground
    fill(210,218,255);
    rect(-1, height-50, width + 1 , 50)

    updateAndDisplayTrees();
    removeTrees();
    addNewTrees(); 

    //person on ground
    push();
    scale(.35, .35);
    image(frames[frameCount % 8], width * 2.75, height * 2.33); 
    pop();
}

//upper mountain
function mountain() {
    var speed = 0.0005;
    var terrain = 0.01;
    stroke(70,119,187);

    for (var x = 0; x < width; x += 1) {
        var t = (x * terrain) + (millis() * speed);
        var y = map(noise(t), 0, 1, 0 + 100, height / 2 + 100);
        line(x, y, x, height); 
    }

    //person on mountain
    push();
    scale(.10, .10);
    image(frames[frameCount % 8], width * 9.85, y * 10 - 100); 
    pop();
}

//lower mountain
function mountain2() {
    var speed = 0.0003;
    var terrain = 0.005;
    stroke(50,99,167);

    for (var x = 0; x < width; x += 1) {
        var t = (x * terrain) + (millis() * speed);
        var y = map(noise(t), 0, 1, height / 2 + 150, height / 4 + 150);
        line(x, y, x, height); 
    }

    //person on mountain
    push();
    scale(.25, .25);
    image(frames[frameCount % 8], width * 3.9, y * 4 - 110); 
    pop();
}

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

function removeTrees(){
    // Copy all the trees we want to keep into a new array.
    var treesToKeep = [];
    for (var i = 0; i < trees.length; i++){
        if (trees[i].x + trees[i].treeWidth > 0) {
            treesToKeep.push(trees[i]);
        }
    }
    trees = treesToKeep; // remember the surviving trees
}

function addNewTrees() {
    // With a very tiny probability, add a new tree to the end.
    var newTreeLikelihood = 0.05; 
    if (random(0,1) < newTreeLikelihood) {
        trees.push(makeTree(width));
    }
}

// method to update position of tree every frame
function treeMove() {
    this.x += this.speed;
}
    
// draw the tree
function treeDisplay() {

    //tree leaves
    fill(22,138,130); 
    noStroke(); 
    push();
    translate(this.x, height - 60);
    triangle(0, -this.treeHeight, 0 - this.treeWidth / 2, 0, 0 + this.treeWidth / 2, 0)
    pop();

    //tree trunk
    fill(40,59,107);
    push();
    translate(this.x, height - 60);
    rect(- 2.5, 0, 5, 10);
    pop();
}

function makeTree(birthLocationX) {
    var tr = {x: birthLocationX,
                treeWidth: random(20,30),
                speed: -5.0,
                treeHeight: random(30,60),
                move: treeMove,
                display: treeDisplay}
    return tr;
}

For this project I spent some time messing around with different colors and mountain heights in order to get a look that I liked.  I couldn’t get the sky to gradient in a way that I thought looked good so I used an image to create the gradient. The trees are at random heights and come at random intervals.  The hardest part was to get the racing people on the right to run along the mountains rather than at a consistent y-value. I had the people decrease in size in order to give a sense of depth, but it was difficult to control the movements of the people once they were scaled down.  Overall, I am pretty happy with this project.

Sketch of concept

Siwei Xie- Project 11 – Landscape

sketch

//Siwei Xie
//Section B
//sxie1@andrew.cmu.edu
//project-10-landscape

var terrainSpeed = 0.0002;//speed of terrian moving
var terrainDetail = 0.015;//smoothness of terrian
var star = [];

function setup() {
    createCanvas(480, 480);
    frameRate(20);//speed of refreshing frames (stars changing)
}

function draw() {
    background("black");

    makeMountain();
    makeMoon();
    makeStar();
    makeCar();
}

//moving terrian
function makeMountain(){
    noStroke();
    fill("blue"); 
    beginShape(); 

    for (var x = 0; x < width; x++) {
      var t = (x * terrainDetail) + (millis() * terrainSpeed);//shape & moving speed of terrian 
      var y = map(noise(t), 0, 1.8, height/8, height);//y-coordinate of terrian
      vertex(x, y);//draw terrian continuously
    }

    vertex(width, height);//constrain range of terrian
    vertex(0, height);//terrian restarts at left side of canvas
    endShape();
}

function makeMoon(){
    noStroke();
    fill(252, 242, 166);
    ellipse(2 * width / 3, height / 4, 120, 120);//outer layer
    fill(239, 207, 104);
    ellipse(2 * width / 3, height / 4, 80, 80);//inner layer
}

function makeStar(){
    fill(270);
    for (var i = 0; i < 30; i++) {
      var starX = random(width); //random stars on upper canvas
      var starY = random(0, 200);
      ellipse(starX, starY, 3, 3);
    }
}

function makeCar(){
    fill("yellow");
    rect(100, random(375, 380), 100, 30);//lower body of shaking car
    rect(100, 350, 70, 30);//uppper body of shaking car

    fill("green");
    stroke("black");
    circle(120, random(410, 415), 30, 30);//left wheel
    circle(170, random(410, 415), 30, 30);//right wheel
}
   

I had fun creating this project. Moving the background (terrain) implies the moving of the main object (car). The process of generating mountain in the back was fascinating, because I learned how to randomize height and width in order to indicate moving scenes. Creating mountains creates a very peaceful and relaxing scene, which is something I desperately want.

I also utilize randomly-positioned stars in the background to make it a starry night. For the car, I used randomized y-coordinates in order to show it is driving on a bumpy road. Overall, I think I achieved my goal of giving the viewer a sense of wonderment.

Sketch on my notebook.