xxxxxxxxxx
104
//Study on large date complications that use separate
//discs for the tens and ones place
//See: https://www.fratellowatches.com/big-date-complication-watches/
//Press:
// 'd' to advance date by one
// 'a' to toggle dial alpha
let dial,
ones,
tens
alphaDial = false;
let now = new Date();
//let day = now.getDate();
let day = 1;
function setup() {
createCanvas(600, 600);
createDial();
createDiscs();
}
function draw() {
background(32);
stroke(255,0,0);
strokeWeight(10);
imageMode(CENTER);
noTint();
let onesPlace = day % 10;
push();
translate(470, height/2);
rotate(-onesPlace * TWO_PI/10.0);
image(ones, 0, 0);
pop();
//tens wheel has eight positions that advance in a funky way
let tensPlace = int(day/5);
push();
translate(161, height/2);
rotate(-tensPlace * TWO_PI/8.0);
image(tens, 0, 0);
pop();
//Overlay the dial:
if (alphaDial) tint(255, 255, 255, 120);
image(dial, width/2, height/2);
}
function createDial() {
dial = createGraphics(400,400);
dial.fill(200);
dial.rect(0,0,400,400);
dial.fill(180,150,130);
dial.noStroke();
dial.rectMode(CENTER);
dial.rect(200,200,220,120);
dial.blendMode(REMOVE);
dial.fill(255,255,255,255);
dial.rect(150,200, 80,80);
dial.rect(250,200, 80,80);
}
function createDiscs() {
ones = createGraphics(320,320);
ones.fill(255,255,255);
ones.noStroke();
ones.ellipse(160,160,320,320);
ones.fill(0);
ones.textSize(90);
ones.textAlign(CENTER);
ones.push();
ones.translate(160, 160);
for (let i = 0; i<10; i++) {
ones.text(i, -120, 30);
ones.rotate(TWO_PI/10);
}
let tensD = 260;
tens = createGraphics(tensD,tensD);
tens.fill(255,255,255);
tens.noStroke();
tens.ellipse(tensD/2,tensD/2,tensD,tensD);
tens.fill(0);
tens.textSize(90);
tens.textAlign(CENTER);
tens.push();
tens.translate(tensD/2, tensD/2);
for (let i = 0; i<8; i++) {
tens.text(int(i/2), tensD/2*0.75, 30);
-tens.rotate(TWO_PI/8);
}
}
function keyPressed() {
if (key=='d') {
day++;
if (day>31) day=1;
}
if (key=='a') alphaDial = !alphaDial;
}