# Miranda-Luong-Project-10

``````/* Miranda Luong
Section E
mluong@andrew.cmu.edu
Project-10: Generative Landscape
*/
var trees  = [];
var hillSpeed = 0.00005;
var hillDetail = 0.005;

function setup() {
createCanvas(640, 240);

// create an initial collection of 30 trees
for (var i = 0; i < 30; i++){
//sets random birthplaceX for trees
var rx = random(width);
trees[i] = makeTree(rx);
}
frameRate(100);
}

function draw() {
background(66, 131, 244);
//sun
noStroke();
fill(225, 145, 90);
ellipse(width-55, 40, 45, 45);
drawHill();
updateAndDisplay();
removeOutOfView();

}

function drawHill(){
noStroke();
fill('green');
beginShape();
vertex(0, height);
for (var x = 0; x < width; x++){
var h = (x * hillDetail)+ (millis() * hillSpeed);
var y = map(noise(h), 0, 1, 0, height);
vertex(x, y);
}
vertex(width,height);
endShape();
}

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

function removeOutOfView(){
// If a tree has dropped off the left edge,
// remove it from the array.  Copy all the buildings
// we want to keep into a new 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; // remember the surviving buildings
}

// With a very tiny probability, add a new tree to the end.
var newTreeLikelihood = 0.007;
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() {
var totalBushHeight = this.nBush * this.bushHeight
noStroke();
push();
translate(this.x, height-100);
for (var i = this.nBush; i > 1; i = i - 1) {
fill(14, 100-(i*5), 39);
}
fill('brown');
pop();
}

function makeTree(birthLocationX) {
var tree = {x: birthLocationX,