jwchou-Project10-GenerativeLandscape

I did not understand how to go about doing this project/had no time this week, so I just created something by modifying the template. I thought it would be better to at least post something rather than nothing. it doesn’t quite work, but it’s what I have.

sketch

var planes = [];

function setup() {
createCanvas(480, 300);

// create an initial collection of buildings
for (var i = 0; i < 10; i++){
var rx = random(width);
planes[i] = makePlane(rx);
}
frameRate(8);
}

function draw() {
background(20, 51, 137);

updateAndDisplayPlanes();
}

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

function removePlanesThatHaveSlippedOutOfView(){
// If a building has dropped off the left edge,
// remove it from the array.  This is quite tricky, but
// we've seen something like this before with particles.
// The easy part is scanning the array to find buildings
// to remove. The tricky part is if we remove them
// immediately, we'll alter the array, and our plan to
// step through each item in the array might not work.
//     Our solution is to just copy all the buildings
// we want to keep into a new array.
var PlanesToKeep = [];
for (var i = 0; i < planes.length; i++){
if (planes[i].x + planes[i].breadth > 0) {
planesToKeep.push(planes[i]);
}
}
planes = planesToKeep; // remember the surviving buildings
}

// With a very tiny probability, add a new building to the end.
var newPlaneLikelihood = 0.01;
if (random(0,1) < newPlaneLikelihood) {
planes.push(makePlane(width));
}
}

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

// draw the building and some windows
function planeDisplay() {
var R = random(100, 200);
var G = random(100, 200);
var B = random(100, 200);
var planeHeight = random(100, 300)
// var bHeight = this.nFloors * floorHeight;
fill(R, G, B);
noStroke(0);
push();
translate(this.x, height - planeHeight);
// rotate(HALF_PI);
fill(R, G, B);
beginShape();
for (var a = 0; a < TWO_PI; a += TWO_PI/5) {
var sx = 0 + cos(a) * 6;
var sy = 0 + sin(a) * 6;
vertex(sx, sy);
sx = 0 + cos(a + TWO_PI/10) * 14;
sy = 0 + sin(a + TWO_PI/10) * 14;
vertex(sx, sy);
}
endShape(CLOSE);
// triangle(40, 40, 45, 50, 50, 40);
}

/*ellipse(40, 40, 70, 11); //wings
ellipse( 40, 20, 35, 8); //horz stabilizer
fill(R, G, B);
ellipse( 40, 40, 17, 45); //fuselage
ellipse( 57,  45, 6, 15); //left engine
ellipse( 23, 45, 6, 15); //right engine
fill(0);
ellipse( 23, 50, 10, 2); //right propeler
ellipse( 57, 50, 10, 2); //left propeller
fill(190);
ellipse( 40, 15, 5, 17); //tail
fill(0);
beginShape(); //cockpit
vertex(35, 50);
vertex( 40, 57);
vertex(45,  50);
vertex(45,  45);
vertex( 40,  50);
vertex( 35,  45);
vertex( 35, 50);
endShape();
pop();*/

function makePlane(birthLocationX) {
var plane = {x: birthLocationX,