Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
35 lines (27 sloc) 1.42 KB
# Clock
Create a timer that ticks every second. This is the time source.
#system/timer = [resolution: 1000, tick: 0, hours: 2, minutes: 32, seconds: 47]
Set up a clock hands table. Degrees is the deflection from noon.
#clock-hands = [|degrees x y stroke|
0 0 0 "#023963"
0 0 0 "#023963"
0 0 0 "#ce0b46"]
## Update the clock
Calculate clock hand angles based on the current time.
time = [#system/timer.hours; #system/timer.minutes; #system/timer.seconds]
multiplier = [30; 6; 6]
#clock-hands.degrees := multiplier * time
Calculate x and y endpoints
angle = #clock-hands.degrees
#clock-hands.x := 150 + (75 * math/sin(degrees: angle))
#clock-hands.y := 150 - (75 * math/cos(degrees: angle))
## Drawing
Set up clock drawing elements
#clock = [|shape parameters|
"circle" [cx: 150 cy: 150 radius: 100 fill: "#0B79CE"]
"line" [x1: 150 y1: 150 x2: #clock-hands{1,2} y2: #clock-hands{1,3} stroke: #clock-hands{1,4}]
"line" [x1: 150 y1: 150 x2: #clock-hands{2,2} y2: #clock-hands{2,3} stroke: #clock-hands{2,4}]
"line" [x1: 150 y1: 150 x2: #clock-hands{3,2} y2: #clock-hands{3,3} stroke: #clock-hands{3,4}]]
Do the draw
clock-canvas = [type: "canvas" class: _ contains: [#clock] parameters: [width: 300 height: 300]]
#app/main = [root: "drawing" direction: "column" contains: [clock-canvas]]
You can’t perform that action at this time.