Project 11

For this project I decided to create a series of clouds and planes which would move across the blue sky. With the amount of time spent indoors the past few months, it’s helpful to remember what it’s like to look up.

sketchDownload
var clouds = [];
var xcNoise = [];
var ycNoise = [];
var scNoise = [];
var planes = [];

function setup() {
    createCanvas(480, 480);
//creating initial number of objects
    for (var i = 0; i < 4; i++){
        var rx = random(width);
        clouds[i] = makeClouds(rx);
    }

    for (var i = 0; i < 2; i++){
        var rx = random(width);
        planes[i] = makePlanes(rx);
    }

    for (var i = 0; i < 20; i++) {
        xcNoise[i] = random(-40,40);
        ycNoise[i] = random(-40,40);
        scNoise[i] = random(60,70)
    }

    frameRate(10);
}


function draw() {
    background(200,215,255);

    updateAndDisplayPlanes();
    updateAndDisplayClouds();
    offScreenPlanes();
    offScreenClouds();
    newPlanes();
    newClouds();
}

//making sure objects move across the screen
function updateAndDisplayClouds(){
    for (var i = 0; i < clouds.length; i++){
        clouds[i].move();
        clouds[i].display();
    }
}
function updateAndDisplayPlanes(){
    for (var i = 0; i < planes.length; i++){
        planes[i].move();
        planes[i].display();
    }
}
//removing objects once they're no longer needed
function offScreenClouds(){
    var cloudsToKeep = [];
    for (var i = 0; i < clouds.length; i++){
        if (clouds[i].x + clouds[i].breadth > 0) {
            cloudsToKeep.push(clouds[i]);
        }
    }
    clouds = cloudsToKeep;
}
function offScreenPlanes(){
    var planesToKeep = [];
    for (var i = 0; i < planes.length; i++){
        if (planes[i].x + planes[i].breadth > 0) {
            planesToKeep.push(planes[i]);
        }
    }
    planes = planesToKeep;
}

//different probabilities for adding new objects
function newClouds() {
    var newCloud = 0.0095;
    if (random(0,1) < newCloud) {
        clouds.push(makeClouds(width+100));
    }
}
function newPlanes() {
    var newPlane = 0.007;
    if (random(0,1) < newPlane) {
        planes.push(makePlanes(width+100));
    }
}
//moving the objects across the screen at different speeds
function cloudMove() {
    this.x += this.speed;
}
function planeMove() {
    this.x += this.speed;
}
//creating the actual objects for clouds and planes
function cloudDisplay() {
    fill(255);
    stroke(0);
    push();
    translate(this.x, this.placement);
    stroke(200);
    noStroke();
    fill(255);
    for (let i = 0; i < this.nFloors; i ++) {
        circle(xcNoise[i], ycNoise[i], scNoise[i]);
    }
    pop();
}

function planeDisplay() {
    push();
    stroke(0);
    fill(0);
    translate(this.x, this.placement);
    ellipse(0,0,40,8);
    triangle(2,0,5,-25,-10,0);
    triangle(2,0,5,25,-10,0);
    triangle(15,0,15,8,10,0);
    triangle(15,0,15,-8,10,0);
    pop();
}

//creating the objects for clouds and planes, and their parameters
function makeClouds(birthLocationX) {
    var cld = {x: birthLocationX,
                breadth: 50,
                speed: random(-2,-.8),
                nFloors: round(random(4,10)),
                move: cloudMove,
                display: cloudDisplay,
                placement: random(0,height)}
    return cld;
}
function makePlanes(birthLocationX) {
    var pln = {x: birthLocationX,
                breadth: 20,
                speed: random(-4,-2),
                move: planeMove,
                display: planeDisplay,
                placement: random(0,height)}
    return pln;
}

Leave a Reply