` 2D Clock
` Coding challenge entry
` Dave Mayes
 
set display mode 640,480,32
sync rate 60
sync on
 
hide mouse
 
cx = screen width () /2
cy = screen height () /2
 
t$=get time$()
s=val(right$(t$,2))
m=val(left$(right$(t$,5),2)) * 60
h=val(left$(t$,2)) * 3600
 
st# = s + m + h - timer() / 1000.0
repeat
    cls
    text 0,0,get time$()
    FOR h = 1 TO 60
        x1 = cx + SIN(h * 6) * (180 + SGN(h MOD 5) * 5)
        y1 = cy - COS(h * 6) * (180 + SGN(h MOD 5) * 5)
        x2 = cx + SIN(h * 6) * 190
        y2 = cy - COS(h * 6) * 190
        LINE x1, y1, x2, y2
        x = cx + SIN(h * 6) * 210
        y = (cy - 8)  - COS(h * 6) * 210
        IF h MOD 5 = 0
            center text x,y,str$(int(h / 5))
        ENDIF
    NEXT h
 
    t# = st# + timer() / 1000.0
    s# = t# * 6
    sx = SIN(s#) * 160
    sy = COS(s#) * 160
    LINE cx, cy, cx + sx, cy - sy
 
    m# = s# / 60
    mx = SIN(m#) * 170
    my = COS(m#) * 170
    LINE cx, cy, cx + mx, cy - my
 
    h# = m# / 12
    hx = SIN(h#) * 120
    hy = COS(h#) * 120
    LINE cx, cy, cx + hx, cy - hy
 
    sync
until scancode() > 0 or abs(mousemovex() > 3) or abs(mousemovey() > 3) or abs(mouseclick() > 0)
 
function SGN(n)
    if n < 0 then n = -1
    if n > 0 then n = 1
endfunction n