/* built with Studio Sketchpad:
* https://sketchpad.cc
*
* observe the evolution of this sketch:
* https://studio.sketchpad.cc/sp/pad/view/ro.AZLayEjqCz6/rev.198
*
* authors:
* Lukasz
* license (unless otherwise specified):
* creative commons attribution-share alike 3.0 license.
* https://creativecommons.org/licenses/by-sa/3.0/
*/
void drawSqare(int x, int y, color c, int sqNo, int data){
if(data&int(sqNo)){
fill(c);
rect(x, y, 20, 20 );
fill(200,200,200);
}
else{
rect(x, y, 20, 20 );
}
}
int hh = 0, mm = 0, ss = 0, h1, h2, m1, m2, s1, s2;
PFont titleFont = loadFont("Courier",18);
PFont smallFont = loadFont("Courier",16);
color red = color(255,0,0);
color green = color(0,255,0);
color blue = color(0,0,255);
void setup() { // this is run once.
background(10,10,10);
size(280, 200);
smooth();
frameRate(10);
strokeWeight(0);
stroke(0,0,0);
}
void draw() { // this is run repeatedly.
//Drawing texts
textFont(titleFont);
fill(255,255,255);
text("Binary clock", 80, 20);
textFont(smallFont);
fill(80,80,80);
text("1",10, 170);
text("2",10, 140);
text("4",10, 110);
text("8",10, 80);
text("HH",60,50);
text("MM",140,50);
text("SS",220,50);
//Ben Fry’s stage: ACQUIRE
//Getting time and calculations
hh = hour();
mm = minute();
ss = second();
//********************
//Ben Fry’s stage: PARSE, FILTER & REFINE
h1 = int(hh/10);
h2 = int(hh%10);
m1 = int(mm/10);
m2 = int(mm%10);
s1 = int(ss/10);
s2 = int(ss%10);
//********************
//Ben Fry’s stage: REPRESENT
//Drawing a clock
fill(200,200,200);
//hours
drawSqare(40, 155, red, 1, h1);
drawSqare(40, 125, red, 2, h1);
drawSqare(70, 155, red, 1, h2);
drawSqare(70, 125, red, 2, h2);
drawSqare(70, 95, red, 4, h2);
drawSqare(70, 65, red, 8, h2);
//minutes
drawSqare(120, 155, green, 1, m1);
drawSqare(120, 125, green, 2, m1);
drawSqare(120, 95, green, 4, m1);
drawSqare(150, 155, green, 1, m2);
drawSqare(150, 125, green, 2, m2);
drawSqare(150, 95, green, 4, m2);
drawSqare(150, 65, green, 8, m2);
//seconds
drawSqare(200, 155, blue, 1, s1);
drawSqare(200, 125, blue, 2, s1);
drawSqare(200, 95, blue, 4, s1);
drawSqare(230, 155, blue, 1, s2);
drawSqare(230, 125, blue, 2, s2);
drawSqare(230, 95, blue, 4, s2);
drawSqare(230, 65, blue, 8, s2);
//********************
}