Analog+Clock

Analog Clock

Has buttons to stop and start the clock. The clock is displayed every second showing the hour,minute, and second hand.

code ' --- ' Analog clock ' --- html "  "

html " " ' gimme someplace to display with a pannel id of pid pid$ = "pid" html " circle here  " gosub [d2] wait

[next] gosub [d2] wait

[pause] if playing <> 0 then stopIt = 1 playing = 0 html " stopTimer; " wait [play] if playing = 0 then playing = 1 html " startTimer; " end if wait

' ' clock. I got nothing but time ' - [d2] if playing = 1 then goto [shoTime] n   = 12 ' num of points r   = 95 ' radius pi   = 22/7 alpha   = pi * 2 / n dim points(n) graphic #g2, 200, 200 ' -- ' Draw the clock ' -- for i = 0 to n - 1 theta = alpha * i   px = cos( theta ) * r    py = sin( theta ) * r    px = px + 100 py = py + 100 #g2 place(px,py) #g2 circle(2) next i
 * 1) g2 size(2) 'pen size
 * 2) g2 down
 * 3) g2 font("arial", 20, "bold")
 * 4) g2 place(85,30)
 * 5) g2 "\12"
 * 6) g2 place(170,105)
 * 7) g2 "\3"
 * 8) g2 place(10,105)
 * 9) g2 "\9"
 * 10) g2 place(90,185)
 * 11) g2 "\6"

[shoTime] ' ' clear previous sec,min,hr ' r   = 63 p   = se gosub [h2Dot] r   = 50 p   = mi gosub [h2Dot] r   = 30 ' radius p   = hr * 5 gosub [h2Dot]
 * 1) g2 color("white")
 * 1) g2 color("white")
 * 1) g2 color("white")

' ' Show new time ' a$   = time$ hr   = val(word$(a$,1,":")) mi   = val(word$(a$,2,":")) se   = val(word$(a$,3,":"))

' put time on the clock - gimme a hand ' second hand n   = 60 r   = 63 p   = se gosub [h2Dot]
 * 1) g2 size(4)
 * 1) g2 color("blue")

' minute hand r   = 50 p   = mi gosub [h2Dot]
 * 1) g2 color("green")

' hour hand r   = 30 ' radius p   = hr * 5 gosub [h2Dot]
 * 1) g2 color("red")

' place graphic and digital time web page html " document.getElementById('";pid$;"').innerHTML = '" render #g2 html "";a$ html "'; " RETURN

' a one liner [h2Dot] alpha   = pi * 2 / n i     = p - 15 theta    = alpha * i px     = cos( theta ) * r py     = sin( theta ) * r px     = px + 100 py    = py + 100 RETURN
 * 1) g2 place(px,py)
 * 2) g2 circle(2)
 * 3) g2 line(100,100,px,py)

code