Analogue watch

Post Reply
Logikmensch
Posts: 17
Joined: Wed Aug 21, 2013 8:02 am

Analogue watch

Post 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
  

User avatar
Mr. Kibernetik
Site Admin
Posts: 4786
Joined: Mon Nov 19, 2012 10:16 pm
My devices: iPhone, iPad, MacBook
Location: Russia
Flag: Russia

Re: Analogue watch

Post by Mr. Kibernetik »

Thanks!
Very nice watch! :)

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

Logikmensch
Posts: 17
Joined: Wed Aug 21, 2013 8:02 am

Re: Analogue watch

Post 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

Post Reply