TEXT   71

clock txt

Guest on 30th June 2022 03:43:48 PM

  1. rem clock
  2. rem copyright Marc Gale (Xalthorn)
  3.  
  4. gosub initialise
  5.  
  6. gosub draw_clock
  7.  
  8. gosub read_time
  9.  
  10. repeat
  11.   gosub flip_screen
  12.  
  13.   gosub draw_time
  14.  
  15.   buttons=peek("port1")
  16.  
  17. until (buttons=16384)
  18.  
  19. exit
  20.  
  21. label draw_clock
  22.   f=pi/180
  23.   for a=1 to 2
  24.     gosub flip_screen
  25.     clear window
  26.     setrgb 1,100,100,100
  27.     circle scx,scy,facesize
  28.  
  29.     for angle=6 to 360 step 6
  30.       if mod(angle,30)=0 then
  31.         setrgb 1,255,255,255
  32.         tx=scx+((facesize+20)*cos((angle-90)*f))
  33.         ty=scy+((facesize+20)*sin((angle-90)*f))
  34.         text tx,ty,str$(angle/30)
  35.  
  36.         inner=0.8
  37.       else
  38.         inner=0.9
  39.       fi
  40.  
  41.       setrgb 1,100,100,100
  42.  
  43.       xs=scx+((facesize*inner)*cos(angle*f))
  44.       ys=scy+((facesize*inner)*sin(angle*f))
  45.       xf=scx+(facesize*cos(angle*f))
  46.       yf=scy+(facesize*sin(angle*f))
  47.       line xs,ys to xf,yf
  48.     next angle
  49.   next a
  50. return
  51.  
  52. label read_time
  53.   dim cut$(1)
  54.   t$=time$
  55.  
  56.   num=token(t$,cut$(),"-")
  57.  
  58.   h$=cut$(1)
  59.   m$=cut$(2)
  60.   s$=cut$(3)
  61. return
  62.  
  63. label draw_time
  64.   gosub undraw_hands
  65.   gosub read_time
  66.  
  67.   setrgb 1,255,255,255
  68.   text 320,380,h$+":"+m$+":"+s$
  69.  
  70.   seco=val(s$)
  71.   rs=int(facesize*0.7)
  72.   as=seco*6
  73.   ws=0
  74.  
  75.   minu=val(m$)
  76.   rm=int(facesize*0.6)
  77.   am=(minu*6)+int(seco/10)
  78.   wm=6
  79.  
  80.   hour=val(h$)
  81.   if hour>12 then hour=hour-12 fi
  82.   rh=int(facesize*0.4)
  83.   ah=(hour*30)+int(minu/2)
  84.   wh=8
  85.  
  86.   gosub draw_hands
  87. return
  88.  
  89. label undraw_hands
  90.   setrgb 1,0,0,0
  91.   fill circle scx,scy,(facesize*0.8)
  92. return
  93.  
  94. label draw_hands
  95.   setrgb 1,0,150,0
  96.   ang=ah
  97.   r=rh
  98.   w=wh
  99.   gosub draw_hand
  100.  
  101.   setrgb 1,0,0,150
  102.   ang=am
  103.   r=rm
  104.   w=wm
  105.   gosub draw_hand
  106.  
  107.   setrgb 1,150,0,0
  108.   ang=as
  109.   r=rs
  110.   w=ws
  111.   gosub draw_hand
  112. return
  113.  
  114. label draw_hand
  115.   f=pi/180
  116.   ang=ang-90
  117.   xs=scx+((r*0.25)*cos((ang-180)*f))
  118.   ys=scy+((r*0.25)*sin((ang-180)*f))
  119.   xl=scx+(w*cos((ang-90)*f))
  120.   yl=scy+(w*sin((ang-90)*f))
  121.   xr=scx+(w*cos((ang+90)*f))
  122.   yr=scy+(w*sin((ang+90)*f))
  123.   xf=scx+(r*cos(ang*f))
  124.   yf=scy+(r*sin(ang*f))
  125.  
  126.   if w=0 then
  127.     line xs,ys to xf,yf
  128.   else
  129.     fill triangle xs,ys to xl,yl to xr,yr
  130.     fill triangle xl,yl to xr,yr to xf,yf
  131.   fi
  132. return
  133.  
  134. label flip_screen
  135.   setdispbuf d
  136.   d=1-d
  137.   setdrawbuf d
  138. return
  139.  
  140. label initialise
  141.   sw=640
  142.   sh=512
  143.   scx=sw/2
  144.   scy=sh/2
  145.   facesize=int(scy/4)*3
  146.  
  147.   d=1
  148.  
  149.   poke "textalign","cc"
  150.   open window sw,sh
  151.   clear window
  152. return

Raw Paste


Login or Register to edit or fork this paste. It's free.