Main Menu

Analogue Clock

Started by jimwon, March 09, 2009, 04:52:43 AM

Previous topic - Next topic

jimwon

A little snippet what will draw an analogue clock at specified co-ords and size:

PlayBASIC Code: [Select]
;Set the Clock Colours
Constant Black=RGB(0,0,0)
Constant DarkGrey=RGB(80,80,80)
Constant White=RGB(255,255,255)
Constant Red=RGB(230,0,0)

;Main Loop
Do
;Clear the Screen
CLS Black
;Position the Clock at 100,100 with a radius of 70
Clock(100,100,70)

; Show the screen
Sync
Loop


Function Clock(X,Y,R)
;Draw the Clock
CircleC X,Y,R,1,DarkGrey
CircleC X,Y,(R-2),1,Black
;Work out the Seconds Hand
SecondsAngle#=270+(CurrentSecond()*6)
SecondsX#=X+Cos(SecondsAngle#)*(R-(R/8))
SecondsY#=Y+Sin(SecondsAngle#)*(R-(R/8))
;Draw the Seconds Hand
LineC X,Y,SecondsX#,SecondsY#,Red
;Work out the Minutes Hand
MinutesAngle#=270+(CurrentMinute()*6)
MinutesX#=X+Cos(MinutesAngle#)*(R-(R/6))
MinutesY#=Y+Sin(MinutesAngle#)*(R-(R/6))
;Draw the Minutes Hand
LineC X,Y,MinutesX#,MinutesY#,White
;Work out the Hours Hand
HoursAngle#=270+(CurrentHour()*30)
HoursX#=X+Cos(HoursAngle#)*(R-(R/4))
HoursY#=Y+Sin(HoursAngle#)*(R-(R/4))
;Draw the Hours Hand
LineC X,Y,HoursX#,HoursY#,White
EndFunction





Related Examples

 Plotting the Second Hand on a clock


geecee

Good one jimwon

;)
geecee
LANG MEY YER LUM REEK

A smile costs less than electricity and gives more light :)