Skip to content

Instantly share code, notes, and snippets.

@samizdatco
Created September 22, 2018 19:12
Show Gist options
  • Save samizdatco/805844386d8556a8083db22494f47dbd to your computer and use it in GitHub Desktop.
Save samizdatco/805844386d8556a8083db22494f47dbd to your computer and use it in GitHub Desktop.
function draw() {
// get the current time
var now = clock()
// set the width & height of the sketch
createCanvas(800, 600)
background(51);
// use the `sec`, `min`, `hours`, and `day` numbers (which are all in the range 0-59, 0-23, or 1-31) to draw
// boxes. the width argument to rect() is always: <some number of pixels> multiplied by <a time component>
//seconds
fill('red');
noStroke();
rect(0, 0, 5 * now.sec, 600);
//minutes
fill('orange');
noStroke();
rect(300, 0, 5 * now.min, 600);
//hours
fill('yellow');
noStroke();
rect(600, 0, 2 * now.hours, 600);
//days
fill('cyan');
noStroke();
rect(650, 0, now.day, 600);
// use the `progress` values (which are always between 0.0 and 1.0) and draw an arc by subdividing the whole
// circle (aka 2*π) by the current fraction of the given time period
//week
fill(0,0,0,0);
stroke(255);
strokeWeight(4);
arc(400, 300, 250, 250, 0, 2*PI*now.progress.week);
//month
fill(0,0,0,0);
stroke(255);
strokeWeight(4);
arc(400, 300, 300, 300, 0, 2*PI*now.progress.month);
// year or seasons
fill(0,0,0,0);
stroke(255);
strokeWeight(4);
arc(400, 300, 550, 550, 0, 2*PI*now.progress.season);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment