BlitzCoder Essentials
•
Home Page
•
About BlitzCoder
•
Contributors
•
Terms of Use
•
Email Us
Main Areas
•
BlitzCoder Chat
•
Discussions
•
Articles/Tutorials
•
Code Database
•
Link Database
•
Showcase Area
•
Worklogs
•
Competitions
Special Areas
•
Undocumented
Other Blitz Sites
•
Blitz Basic Home
•
Blitz Showcase
•
BlitzPlay Library
Forum Login
Username:
Password:
•
Register Now!
BlitzCoder Code Archives Page
Main Codes Page
"Analogue clock"
, by metalman
Simple commented code that shows how to create an analogue clock in Blitz. Was about to delete it when I thought it perhaps could be usefull to someone...
Code
AppTitle "Clock" Graphics 320,240,16,2 Const radius%=100 ; Radius of circle Const ClockX%=60 ; XPos of Clock Const ClockY%=25 ; YPos of Clock Const HourMarkerSize%=10 ; Size of circles that represent hours on the clock face Const MarkerOffset%=10 ; How far to the middle of the clock the markers should be positioned Const HourPointerLen%=70 ; Length of HourPointer Const MinutePointerLen%=90 ; Length of MinutePointer Const SecondPointerLen%=90 ; Length of SecondPointer ; Gets the current Hour Function HourOfTime%() Return Int(Left(CurrentTime(),2)) End Function ;Gets the current minute Function MinuteOfTime%() Return Mid(CurrentTime(),4,2) End Function ;Gets the current second Function SecondOfTime%() Return Right(CurrentTime(),2) End Function ; Draws the static parts of the clock Function drawclockface() Color 255,255,255 ; set drawing color to white for clock Oval ClockX,ClockY,Radius*2,Radius*2,False ; draw the clock midX%=ClockX+Radius ; This is to get the middle X point midY%=ClockY+Radius ; This is to get the middle Y point Color 255,0,0 ; Red for hour markers For agl%=0 To 360 Step Int(360/12) ; loop to set the hour markers (360/12 is how many degrees between every hour) offsX%=midx+((Radius-MarkerOffset)*Sin(agl)) ; Calculate X position of hour marker offsY%=midy+((Radius-MarkerOffset)*Cos(agl)) ; Calculate Y position of hour marker Oval offsx-Int(HourMarkerSize/2),offsy-Int(HourMarkerSize/2),HourMarkerSize,HourMarkerSize ; Draw the Marker Next Oval midx-1,midy-1,2,2 ; Just to mark the middle of the clock End Function ; Calculates and Displays the pointers Function renderclock() drawclockface() ; Draw the 'static' parts midX%=ClockX+Radius midY%=ClockY+Radius hh%=HourOfTime() ; Current Hour mm%=MinuteOfTime() ; Current Minute ss%=SecondOfTime() ; Current Second ssAgl%=360/60 ; Angle per Seconds ssAgl%=ssAgl*ss ; Angle for current second ssAgl=ssAgl-180 ; This is to sync second 0 with 0 on the clock px% = midX-SecondPointerLen*Sin(ssagl) ; Xpos for the tip of the pointer for seconds py% = midY+SecondPointerLen*Cos(ssagl) ; Ypos for the tip of the pointer for seconds Line midX,midY,px,py Color 0,255,0 mmAgl%=360/60 ; Angle per minute mmAgl%=mmAgl*mm ; Angle for current second mmAgl=mmAgl-180 ; This is to sync minute 0 with 0 on the clock px% = midX-minutePointerLen*Sin(mmagl) ; Xpos for the tip of the pointer for minutes py% = midY+minutePointerLen*Cos(mmagl) ; Ypos for the tip of the pointer for minutes Line midX,midY,px,py Color 0,0,255 hhAgl%=360/12 ; Angle per hour hhAgl%=hhAgl*hh ; Angle for current hour hhAgl=hhAgl-180 ; This is to sync hour 0 with 0 on the clock px% = midX-hourPointerLen*Sin(hhagl) ; Xpos for the tip of the pointer for seconds py% = midY+hourPointerLen*Cos(hhagl) ; Ypos for the tip of the pointer for seconds Line midX,midY,px,py End Function SetBuffer BackBuffer() While Not KeyDown(1) Cls renderclock() Color 255,255,255 Text 160,0,"Hit Esc to close",True,False Flip Wend
Copyright(c) 2000-2004, BlitzCoder. All Rights Reserved.
Code software created by Krylar's Kreations