*

\ the clock using angle as virtual needles

\ range changed from [0,2pi] to [0,1] for the angle
: 2pi 2 pi * ; : cos 2pi * cos ;
: atan2 atan2 2pi / 1 mod ;
\ the origin moved to the square center
: x x .5 - ; : y y .5 - ;
\ the distance from the origin to any point x,y
: r ( -- radius ) x 2 ** y 2 ** + .5 ** ;
\ the angle from origin to any point x,y
: a ( -- angle ) y x atan2 ;
\ the angle for n seconds
: s ( #seconds -- angle ) t floor swap / ;
\ the angle for n minutes
: m ( #minutes -- angle ) 60 s swap / ;
\ the angle for n hours
: h ( #hours -- angle ) 60 m swap / ;
\ the virtual needle for given angle and radius
: n ( angle radius -- needle ) r > swap a .25 - + 1 mod * ;
\ n ticks to form a whole circle
: t ( #ticks/circle -- ticks ) 2 / a * cos 999 ** r .45 > * r .49 < * ;
\ the red needle for the seconds with 4 ticks
60 s .4 n 4 t +
\ the green needle for the minutes with 12 ticks
60 m .3 n 12 t +
\ the blue needle for the hours
12 h .2 n

comments powered by Disqus