Project 06: Clock

sketch

//Name: Hari Vardhan Sampath
//Section: E
//eMail address: harivars@andrew.cmu.edu
//Project-06

function setup() {
    createCanvas(450, 300);
}

function draw() {
    var s = map(second(), 0, 60, 0 , width); //runs from left to right
    var m = map(minute(), 0, 60, 0 , width); //runs from left to right
    var h = map(hour(), 0, 24, height , 0); //runs from bottom to top
    var cR;
    var cG;
    var cB;
    // color caliberation for the background w.r.t. hour
    if (hour() > 0 & hour() < 6) {
        cR = 0;
        cG = 50;
        cB = 100;
    }
    else if (hour() > 6 & hour() < 15) {
        cR = 50;
        cG = 150;
        cB = 250;
    }
    else if (hour() > 15 & hour() < 19) {
        cR = 50;
        cG = 150;
        cB = 250;
    }
    else if (hour() > 19 & hour() < 24) {
        cR = 0;
        cG = 25;
        cB = 51;
    }
    background(cR, cG, cB); // cliberated background

    // grid for second
    for (var xS = 0; xS <= width; xS += width/60) {
        stroke('rgba(10, 10, 10, 0.9)');
        strokeWeight(1);
        line(xS, 200, xS, height);
    }
    // grid for minute
    for (var xM = 0; xM <= width; xM += width/60) {
        stroke('rgba(10, 10, 10, 0.9)');
        strokeWeight(4);
        line(xM, 100, xM, 200);
    }
    // grid for hour
    for (var xH = 0; xH <= width; xH += height/24) {
        stroke('rgba(10, 10, 10, 0.9)');
        strokeWeight(10);
        line(width/2, xH, width - height/2, xH);
    }
    // second runs along the horizontal grid left to right
    push();
    stroke(cR, cG, cB);
    strokeWeight(2);
    line(s, 200, s, height);
    pop();
    // minuit runs along the horizontal grid from left to right
    push();
    stroke(cR, cG, cB);
    strokeWeight(3);
    line(m, 100, m, 200);
    pop();
    // hour runs along the vertical grid from bottom to top 
    push();
    stroke(cR, cG, cB);
    strokeWeight(9);
    line(width/2, h, width - height/2, h);
    pop();
}

Leave a Reply