Carley Johnson Project 10

sketch

/*Carley Johnson
Section E
cbjohnso@andrew.cmu.edu
Project 9
*/

 
var stripes = [];
var offset = 0;
 
function newStripe(px, py, ph) {
    color: setColor();
    return {x: px, y: py, h: ph};
}

function setColor(){
    return color(random(1, 255), random(1, 255), 70);
}
 
 
function setup() {
    createCanvas(480, 300);
      stripes.push(newStripe(600, 200, 200));
}

function stripeRight(p) {
    return p.x + p.h;
}

function stripeLast() {
    return stripes[stripes.length - 1];
}
 
function draw() {
    background("lightblue");
    
    stroke(0);
    for (var i = 0; i < stripes.length; i++) {
        var p = stripes[i];
        fill((random(0, 255)),(random(0, 255)), (random(0, 255)));
        rect(p.x - offset, 0, 50, p.h + 100);
    }
 

    if (stripes.length > 0 & stripeRight(stripes[0]) < offset) {
        stripes.shift();
    }
 
    if (stripeRight(stripeLast()) - offset < width) {
        var p = newStripe(stripeRight(stripeLast()),
                            random(50, 225), 
                            200); 
        stripes.push(p); 
    }
 
    offset += 1;
}
 

Lol seizure warning honestly.

The idea was to have moving stripes in a pattern, creating a sort of ever-changing wallpaper. I got the moving landscape working alright, but missed how to assign one color to one stipe, so now it’s a psychadellic wallpaper I guess

Leave a Reply