mjanco – Section B – Project 10

sketch

//Michelle Janco
//Section B
//mjanco@andrew.cmu.edu
//Project10

var blobs = [];
var mountain = .05;
var mountainSpeed = .0009;


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

    // create blobs
    for (var i = 0; i < 10; i++){
        var rx = random(width);
        blobs[i] = makeBlob(rx);
    }
    frameRate(30);
}

function draw() {
    background(240, 215, 87);
    displayHorizon();
    makeMountain();
    updateAndDisplayBlobs();
    removeBlobsThatAreOutOfView();
    addNewBlobsWithSomeRandomProbability();

}

//make mountain
function makeMountain() {
    stroke(1);
    fill(240, 160, 34);
    beginShape();
    for (var i = 0; i < width; i++) {
        var x = (i * mountain) + (millis() * mountainSpeed);
        var y = map(noise(x), 0, 1, height/7, height/2);
        vertex(i, y);
    }
    vertex(width, height-height/4);
    vertex(0, height-height/4);
    endShape();
}

function displayHorizon(){
    strokeWeight(3);
    stroke(0);
    line (0,height-height/4, width, height-height/4);
}


function updateAndDisplayBlobs(){
    // update blobs' positions, display them
    for (var i = 0; i < blobs.length; i++){
        blobs[i].move();
        blobs[i].display();
    }
}


function removeBlobsThatAreOutOfView(){
    var blobsToKeep = [];
    for (var i = 0; i < blobs.length; i++){
        if (blobs[i].x + blobs[i].breadth > 0) {
            blobsToKeep.push(blobs[i]);
        }
    }
    blobs = blobsToKeep;
}


function addNewBlobsWithSomeRandomProbability() {
    //small probability, add a new tree to the end
    var newBlobLikelihood = 0.010;
    if (random(0,1) < newBlobLikelihood) {
        blobs.push(makeBlob(width));
    }
}


//update position of blob
function blobMove() {
    this.x += this.speed;
}


//draw blob
function blobDisplay() {
    var blobHeight = random(5, 15);
    var bHeight = (random(15, 30));
    fill(255);
    noStroke();
    push();
    translate(this.x, height - 40);
    ellipse(0, -bHeight, this.breadth, bHeight);
    ellipse(0, bHeight, this.breadth, bHeight);
    stroke(200);
    pop();
}


function makeBlob(birthLocationX) {
    var blo = {x: birthLocationX,
                breadth: 50,
                speed: -4.0,
                nBlo: round(random(2,8)),
                move: blobMove,
                display: blobDisplay}
    return blo;
}

For this project I wanted to make some sort of reflection, and was able to get my abstract blobs to have their own reflections on this mysterious glass like surface. I wanted to make something not too literal or specific, and just focus on using what I’ve learned since I found it difficult. But I still found the end result mysterious and ambiguous which is what I like.

Leave a Reply