Zee Salman- Project 11- Landscape

sketch

// Zee Salman
//fawziyas@andrew.cmu.edu
//Project-11
//section E

var trees = []
var terrain = 0.005;
var midTerrain = 0.016;
var lowTerrain = 0.020;
var terrainSpeed = 0.0004;
var rate = 0.007; 

function setup() {
    createCanvas(400, 400);
    frameRate(300);  
    }
function draw() {
    //background 
    fill(163,221,255);
    rect(0,0,width,height);
    
    //sun 
    noStroke();
    fill(255,228,26);  
    ellipse(width-60, 70, 80, 80);
    
    //mountain 
    mountains(); 
    addT();
    removeT();
    newT();
    ground(); 
}


function removeT(){
    //takes away trees
    var treesKeep = [];
    for (var i = 0; i < trees.length; i++){
        if (trees[i].x + trees[i].breadth > 0) {
            treesKeep.push(trees[i]);
        }
    } 
    trees = treesKeep;
}



function addT(){
    // x coordinate 
    for (var i = 0; i < trees.length; i++){
        trees[i].move();
        trees[i].display();
    }
}


function newT() {
    // new tree on screen
    if (random(0,1) < rate) {
        trees.push(drawT(width));
    }
}


function treesMove() {
    this.x += this.speed;
}
    
//show trees
function treesDisplay() {
    
    //bottom
    strokeWeight(8);
    stroke(120, 79, 25);
    line(this.x, 350, this.x, 420);

    //top
    noStroke();
    fill(48,67,7);
    triangle(this.x - 30, 360, this.x + 30, 360, this.x, 300);
}


function drawT(px) {
    var bx = {x: px,
                breadth: 20,
                speed: -1.0,
                move: treesMove,
                display: treesDisplay}
    return bx;
}

function ground() {
    noStroke(); 
    fill("grey");
    rect(0, height-25, width, height/5);
}

function mountains() {
    //creates mountains 
    beginShape(); 
    stroke(43, 99,41);
    for (var x = 0; x < width; x++) {
        var q = (x * terrain) + (millis() * terrainSpeed);
        var m = map(noise(q), 0, .95, 300, 3);
        line(x, m, x, height); 
    }
    endShape();

   
    
    beginShape(); 
    stroke(76, 160, 73);
    for (var x = 0; x < width; x++) {
        var q = (x * midTerrain) + (millis() * terrainSpeed);
        var m = map(noise(q), 0, .75, 250, 200);
        line(x, m, x, height); 
    }
    endShape();

    
    beginShape(); 
    stroke(120, 205, 117);
    for (var x = 0; x < width; x++) {
        var q = (x * lowTerrain) + (millis() * terrainSpeed);
        var m = map(noise(q), 0, 3, 300, 250);
        line(x, m, x, height); 
    }
    endShape();
}



sketch for landscape

I was very interested in this project because it would never be the same when the landscape would pass by. It reminds me of when I go on a road trip and stick my head out the car window. The scenes change all the time. That is where I got my inspiration from to do this project.

Leave a Reply