-
Notifications
You must be signed in to change notification settings - Fork 0
/
shapes_clock.js
53 lines (46 loc) · 1.38 KB
/
shapes_clock.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// setup() is called once at page-load
function setup() {
createCanvas(400, 300); // make an HTML canvas element width x height pixels
hrColor = color(120, 30, 150);
minColor = color(150, 50, 200);
secColor = color(190, 90, 220);
innerColor = color(220, 140, 255);
spacing = 133; // spacing between shapes
sizeOfShapes = 65 // size of shapes
}
// draw() is called 60 times per second
function draw() {
background(235);
drawShapesAccordingToTime();
}
// function for drawing time grids
function drawShapesAccordingToTime() {
drawShapes(hour(), sizeOfShapes, hrColor, width / 2 - spacing, height / 2);
drawShapes(minute(), sizeOfShapes, minColor, width / 2, height / 2);
drawShapes(second(), sizeOfShapes, secColor, width / 2 + spacing, height / 2);
}
function drawShapes(sides, radius, col, x, y) {
let angle = TWO_PI / sides;
push();
translate(x, y);
fill(col);
// Draw the shape based on time
beginShape();
for (let i = 0; i < sides; i++) {
let px = cos(i * angle) * radius;
let py = sin(i * angle) * radius;
vertex(px, py);
}
endShape(CLOSE);
// Draw lines from each vertex to the center
for (let i = 0; i < sides; i++) {
let px = cos(i * angle) * radius;
let py = sin(i * angle) * radius;
line(0, 0, px, py);
}
// If sides is 0, draw a dot at the center
if (sides === 0) {
ellipse(0, 0, 2, 2);
}
pop();
}