xxxxxxxxxx
36
//Setup global settings
function setup() {
let w = windowWidth;
let h = windowHeight;
createCanvas(w, h);
textAlign(CENTER);
textSize(w / 6);
frameRate(1);
}
function draw() {
//declare time variables
let hr;
let mn;
let scnd;
let time;
//set locations and colors
background(int(random(255)), int(random(255)), int(random(255)));
fill(int(random(255)), int(random(255)), int(random(255)));
translate(width / 2, height / 2);
//formatting conditional logic
hr = hour() > 12 ? hour() - 12 : hour();
mn = minute() < 10 ? `0${minute()}` : minute();
scnd = second() < 10 ? `0${second()}` : second();
time = hour() > 11 ? `${hr}:${mn}:${scnd} PM` : `${hr}:${mn}:${scnd} AM`;
//draw sketch
text(time, 0, 0);
}