Page 1 of 1

Analogue watch

Posted: Wed Aug 21, 2013 3:28 pm
by Logikmensch
Dear readers,

in respect of this wonderful Basic system I've programmed an analogue watch only for my (and your) pleasure. Of course it's device independant. :-)

Code: Select all

' watch by Claus Jahn
  t=15
  pi=3.1415926
  graphics
  shadow on

loop:
  graphics lock
  graphics clear 1,1,1
  width=screen_width()
  height=screen_height()
  cx=width/2
  cy=height/2
  draw color 0.5,0.5,0.5
  fill color 1,0.75,0.75
  draw size t
  if width>height then
    sz=cy-t
  else
    sz=cx-t
  end if
  fill circle cx,cy size sz
  draw circle cx,cy size sz
  draw font size 20
  draw size 2
  for z=0 to 11
    h=(z-3)/6*pi
    i=sz*13/16
    if z=0 then u$="12" else u$=z
    draw text u$ at cx+i*cos(h)-5*len(u$),cy+i*sin(h)-10
    i=sz*15/16
    j=sz*14/16
    draw line cx+i*cos(h),cy+i*sin(h) to cx+j*cos(h),cy+j*sin(h)
  next z
  seconds=current_second()
  minutes=current_minute()
  hours=current_hour()
  if hours>12 then hours=hours-12
' drawing hours
  h=(hours-3)/6*pi
  i=sz*0.5
  draw color 0,0,1
  draw size 5
  draw line cx,cy to cx+i*cos(h),cy+i*sin(h)
  
' drawing minutes
  h=(minutes-15)/30*pi
  i=sz*4/5
  draw color 0,1,0
  draw size 2
  draw line cx,cy to cx+i*cos(h),cy+i*sin(h)

' drawing seconds
  h=(seconds-15)/30*pi
  i=sz*4/5
  draw color 1,0,0
  draw size 1
  draw line cx,cy to cx+i*cos(h),cy+i*sin(h)
  
  graphics unlock
  goto loop
  

Re: Analogue watch

Posted: Wed Aug 21, 2013 3:59 pm
by Mr. Kibernetik
Thanks!
Very nice watch! :)

I would suggest to make hour line thicker or draw it after minute line.

Re: Analogue watch

Posted: Wed Aug 21, 2013 4:09 pm
by Logikmensch
okay,
I also did not take care about the fact that usually, the minute line should be increased by the seconds and the hour line by the minutes. The following addition could correct this:

Code: Select all

  seconds=current_second()
  minutes=current_minute()
  hours=current_hour()
  minutes=minutes+seconds/60
  hours=hours+minutes/60