PROJECT-05 (wallpaper)

sketch
// SEAN CHEN
// 15-104 A

function setup() {
    smooth();
    createCanvas(600, 1000);
    background(255,194,130);
}

function poka(scale) { // background pokadots
    for (var i = 0; i < scale/2; i++){ // array columns
        noFill();
        var w =  width / scale;
        var h = height / scale;
        push();
        translate(i*(2*w), 0);
        for (var j = 0; j < scale+1; j++){ // drawing a column
            push();
            var r = random(0.4, 0.6); // giving the ellipse rand sizes
            translate (0, j*h); // vert column of random ellipse
            ellipse (w/2, h/2, r*w, r*h);
            translate (w, h/2-h) // shifted vert column of rand ellipse
            ellipse (w/2, h/2, r*w, r*h);
            pop();
        }
        pop();
    }
}


function leaf() { // drawing a little leaf (mint color)
    stroke(88,216,169);
    strokeWeight(5);
    line(-10, 0, 10, 0);
    line(-5, -5*sqrt(3)/2, 5, 5*sqrt(3)/2);
    line(-5, 5*sqrt(3)/2, 5, -5*sqrt(3)/2);
}

// drawing a small branch from a certain x,y
// (same as stem func)
function miniStem(x, y) { 
    noStroke();
    fill(94,59,24)
    for (var i = 0; i < 25; i++) {
        rectMode(CENTER);
        square(x, y+i, 5);
        if (i == 20) { // right before the end of the branch
            push();
            translate(x, y+i); // move leaf to that coordinate
            leaf(); // draw leaf
            pop();
        }
        x += random(-5, 5);
    }
}

function stem(maxH) {
    noStroke();
    fill(94,59,24)
    var x = 50 // center pt for each tile
    for (var i = 0; i < maxH; i++) {
        if (i < maxH-25) { // before getting to last 25 "pixels"
            rectMode(CENTER); // square using center
            square(x, i, 5); // drawing sqaure at x, i which is shifting down
            x += random(-3, 3); // aggregate the branches left and right
        } else {
            square(x, i, 5); // drawing squre
            var diff = x-50; // difference from center
            x += -1*(diff/15); // shifting x back to center for seamless
        }
        var y = i; // for ministem
        if (i%50 == 0) { // every 50 "pixels" downward add a small branch
            miniStem(x, y);
        }
    }
}

function draw() {
    poka(50); // add pokadot bg
    for (var i = -2; i < 9; i++) { // tiling of the branches
        push();
        translate (100*i, 0);
        for (var j = -2; j < 9; j++) {
            push();
            translate (0, 200*j);
            stem(200);
            pop();
        }
        pop();
    }
    noLoop();
}

Leave a Reply