set display mode 800,600,32
 
sync on
 
 
cx = 150
cy = 150
radius = 50
 
secHandLength = 50
minHandLength = 40
hourHandLength = 30
 
 
 
repeat
   cls
 
 
   if mouseclick() = 1
      mx = mousex()
      my = mousey()
   endif
 
 
   for x = cx-radius to cx+radius
      for y = cy-radius to cy+radius
         ink rgb(255,0,0),0
         `dot x,y
         if (x-cx)^2 + (y-cy)^2 <= radius^2
            p# = ((mx-x)^2 + (my-y)^2+0.0) / radius^2
            if p# > 1 then p#=1.0
            ink getTransitionalColor(rgb(225,225,225),rgb(28,28,28),p#),0
            dot x,y
         endif
      next y
   next x
 
   circleOutline(cx,cy,radius+16,radius)
 
   rem draw numbers on clock
   ink rgb(52,78,98),0
   for n = 1 to 12
      a# = wrapvalue(360*(n/12.0)-90)
      nx = (cx+cos(a#)*(radius+7)) - text width(str$(n))/2.0
      ny = (cy+sin(a#)*(radius+7)) - text height(str$(n))/2.0
      text nx,ny,str$(n)
   next n
 
   rem calculate current seconds
   time$ = get time$()
   seconds = val(right$(time$,2))
   rem calculate angle of 'seconds' hand on clock
   angle# = wrapvalue((360*(seconds/60.0))-90)
   tx = cx+cos(angle#)*secHandLength
   ty = cy+sin(angle#)*secHandLength
   ink rgb(0,255,0),0
   line cx,cy,tx,ty
 
   rem calculate current minutes
   minutes = val(mid$(time$,4)+mid$(time$,5))
   angle# = wrapvalue(360*(minutes/60.0)-90)
   tx = cx+cos(angle#)*minHandLength
   ty = cy+sin(angle#)*minHandLength
   ink rgb(0,0,255),0
   line cx,cy,tx,ty
 
 
   rem calculate current hour
   hour = val(left$(time$,2))
   if hour > 12 then hour = hour-12
   angle# = wrapvalue(hour*30+(30*(minutes/60.0))-90)
   tx = cx+cos(angle#)*hourHandLength
   ty = cy+sin(angle#)*hourHandLength
   ink rgb(0,255,255),0
   line cx,cy,tx,ty
 
 
 
   set cursor 0,0
   print "FPS: ",screen fps()
   print "Hour: ",hour
   print "Min: ",minutes
   print "Sec: ",seconds
 
   sync
until spacekey()
 
 
 
REM **************************************************
REM Draws the outline of a circle given the center
REM co-ordinates [cx,cy] and its inner and outer radii
REM **************************************************
function circleOutline(cx,cy,outerRadius,innerRadius)
   for x = cx-outerRadius to cx+outerRadius
      for y = cy-outerRadius to cy+outerRadius
         sqDistance = (cx-x)^2 + (cy-y)^2
         if  sqDistance <= outerRadius*outerRadius and sqDistance >= innerRadius*innerRadius
            p# = (((x-cx)^2 + (y-cy)^2+0.0) - innerRadius^2) / (outerRadius^2-innerRadius^2)
            if p# > 1 then p#=1.0
            ink getTransitionalColor(rgb(188,194,200),rgb(46,51,55),p#),0
            dot x,y
         endif
      next y
   next x
endfunction
 
REM **************************************************
REM Returns a linear interpolated color between base
REM color and target color. Percent ranges from 0 to 1
REM **************************************************
function getTransitionalColor(base, target, percent#)
   br = rgbr(base)
   bg = rgbg(base)
   bb = rgbb(base)
   tr = rgbr(target)
   tg = rgbg(target)
   tb = rgbb(target)
   tr = br + (tr-br)*percent#
   tg = bg + (tg-bg)*percent#
   tb = bb + (tb-bb)*percent#
   color = rgb(tr,tg,tb)
endfunction color