P-06 Abstract Clock

sketch
// Bridget Doherty
// bpdohert@andrew.cmu.edu 
// 104 Section C


function setup() {
    createCanvas(480, 480);
    frameRate(5);
    angleMode(DEGREES);
}

function draw() {
    background(0); // black background
    translate(width/2, height/2); // center-based coordinates

    let s = second();
    let m = minute();
    let h = hour();

    drawStars(h);
    drawEarth(s);
    drawSun(h);
    
}

function drawSun(h){
    if (h == 0) { // eclipse every night from 00:00 - 00:59
        fill('black');
        strokeWeight(2);
        stroke('white');
        circle(0, 0, 100);
    } else {
        fill('yellow'); // the sun!
        noStroke();
        circle(0, 0, 100);
    }
}

function drawEarth(s){ // the earth completes a rotation every minute
    noStroke(); // and moves every second
    push();
    rotate(s*6);
    fill('blue');
    circle(150, 0, 70);

    // triangles to approximate land on earth 
    fill('green');
    triangle(170, 0, 120, 0, 150, 20);
    triangle(170, 10, 130, 10, 120, 20);
    triangle(175, -10, 130, -20, 120, 10);

    // ellipse to approximate Antarctica
    fill(220);
    ellipse(150, -30, 30, 10);
    pop();
}

function drawStars(h){ // the amount of stars increases every hour
    for (var i = 0; i<(h*10); i++){ // there are no stars between 00:00 and 00:59
        stroke('white');
        point(random(-width/2,width/2), random(-width/2, width/2));
    }
}

This is obviously based on Earth’s rotation around the sun, but condensed so it makes one revolution every minute. The number of stars increase with every hour passed. Every night from 00:00-00:59 there is a solar eclipse which is so naturally impossible with how I’ve set up the scene but looks cool nonetheless.

Leave a Reply