News:

Building a 3D Ray Tracer  By stevmjon

Main Menu

Plotting the Second Hand on a clock

Started by kevin, October 11, 2008, 06:17:04 PM

Previous topic - Next topic

kevin

 Plotting the Second Hand on a clock

  This example converts the current second into an angle, so we can draw a representation of a second hand on a clock.  Might be useful for games that use timers

PlayBASIC Code: [Select]
ClockXpos=400
ClockYpos=300

do

cls 0

; draw an open circle at 400x,300y with a radius of 100
circle ClockXpos,ClockYpos,100,false

; get the current seconds
Seconds=currentSecond()
; convert the seconds into an angle
Angle#=(360*(Seconds/60.0))-90

; calc the end of the second hands end
HandEndX=ClockXpos+Cos(Angle#)*90
HandEndY=ClockYpos+Sin(Angle#)*90

; draw it
line ClockXpos,ClockYpos,HandEndX,HandEndY

; display the seconds count
print seconds

sync
loop





Related Examples
 Analogue Clock  


kevin

#1
 Drawing a Speedo


PlayBASIC Code: [Select]
setfps 100

MaxSpeed#=200

do

cls 0


if Upkey()=true and CurrentSpeed#<MaxSpeed#
CurrentSpeed#=CurrentSpeed#+2
else
if CurrentSpeed#>0
CurrentSpeed#=CurrentSpeed#-1
endif
endif


Speedo(400,300,100,CurrentSpeed#,MaxSpeed#)

print CurrentSpeed#
print MaxSpeed#

sync
loop



Function Speedo(Xpos,Ypos,Radius,CurrentSpeed#,MaxSpeed#)

; draw an open circle at 400x,300y with a radius of 100
circle Xpos,Ypos,100,false

; convert the speed into an angle from 0-360
Angle#=(360*(CurrentSpeed#/MaxSpeed#))+90

; calc the end of the hands end
HandEndX=Xpos+Cos(Angle#)*90
HandEndY=Ypos+Sin(Angle#)*90

; draw it
line xpos,Ypos,HandEndX,HandEndY

EndFUnction