xxxxxxxxxx
46
function setup() {
// Runs once
createCanvas(300,300)
centrePoint = createVector(width / 2, height / 2)
size = 200 // of clockface
}
function draw() {
// Runs forever
background(220);
// Grab time variables
let m = minute();
let h = hour();
// Make vectors for clock hands
minHand = createVector(0,-80)
hourHand = createVector(0,-50)
// Calculate clock rotation
minRotate = map(m, 0, 60, 0, 360)
hourRotate = map(h, 0, 12, 0, 360)
// Rotate the vector
minHand.rotate(radians(minRotate))
hourHand.rotate(radians(hourRotate))
// Draw the clockface
let c = color(255, 204, 0);
fill(c);
noStroke()
circle(centrePoint.x, centrePoint.y, size);
// Centre black circle
fill(0)
circle(centrePoint.x, centrePoint.y,size/20)
// Draw Minute hand
stroke(0)
strokeWeight(5)
line(centrePoint.x, centrePoint.y, centrePoint.x + minHand.x, centrePoint.y+minHand.y);
// Draw Hour hand
strokeWeight(10)
line(centrePoint.x, centrePoint.y, centrePoint.x + hourHand.x, centrePoint.y+hourHand.y);
}