Project 11

sketchDownload
var hills = [];
var noiseParam = 0;
var noiseStep = 0.03;
var xTree = [];
var yTree = [];
var car;

function preload() {
    car = loadImage("https://i.imgur.com/dk31naF.png");
}

function setup() {
    createCanvas(400, 250);
    for (var i = 0; i <= width/5; i ++) {
        var n = noise(noiseParam);
        var value = map(n, 0, 1, 0 ,height);
        print(n);
        hills.push(value);
        noiseParam += noiseStep;
    }
    frameRate(10);
    imageMode(CENTER);
}

function draw() {
    background(0, 59, 107); //dark sky
    hills.shift();
    var n = noise(noiseParam);
    var value = map(n, 0, 1, 0 ,height);
    hills.push(value);
    noiseParam += noiseStep;
    for (var i = 0; i < width/5; i ++) {
        var x = i*5;
        noStroke();
        fill(22, 105, 120);
        beginShape(); //drawing the hills
        vertex(x, height);
        vertex(x, hills[i]); 
        vertex(x+5, hills[i+1]);
        vertex(x+5, height);
        endShape();
        //draw tree if hillValue[i] is smaller than the points before & after
        if (hills[i] < hills[i+1] && hills[i] < hills[i-1]) {
            tree(x, hills[i]);
        }
    }
    //insert car image
    image(car, width/2, height/2, 450, 300);

}
function tree(x, hills) {
    fill(1, 120, 33)
    triangle(random(x-2, x-5), hills*1.2, random(x, x+3), 
    hills*0.8, x+5, hills*1.2);
    stroke(46, 19, 19);
    strokeWeight(2);
    line(x, hills*1.2, x, hills*1.5); 
}

This animation shows a baby sitting inside a car in the middle of a long drive at night, staring out into the mountains.

Leave a Reply