News:

Function Finder  Find all the functions within source code files

Main Menu

Shape Clock

Started by kevin, January 25, 2005, 10:15:36 AM

Previous topic - Next topic

kevin

This function draws a realizable  clock..  

- EDIT - Fixed a bug + Cleaner version

PlayBASIC Code: [Select]
   w=200   
h=100

cx=300
cy=300

Do
Cls 0

DrawClock(cx,cy,w,h)


if upkey() and H>10 then dec h
if downkey() and H<1000 then inc h

if Leftkey() and w>10 then dec w
if Rightkey() and w<1000 then inc w

Sync
loop




Function DrawClock(cx,cy,Width,height)

Static ShapesCReated,ClockSHape,OldWidth,OldHeight
Local Angle#

if OldWidth<>Width or OldHeight<>height
if SHapesCreated=True
DeleteShape ClockShape
SHapesCreated=False
endif
endif

if SHapesCreated=False
OldWidth=Width
OldHeight=Height

Local edgestep=10
Local edges=360/edgestep

ClockShape=GetFreeShape()
CReateSHape ClockShape,edges+1,edges+1
TempShape=GetFreeShape()
CReateSHape TempShape,edges+1,edges+1

Local VertIndex=1
For Angle#=0 to 359 step edgestep
X#=Cos(angle#)*Width
Y#=Sin(angle#)*Height
SetShapevertex ClockShape,VertIndex,x#,y#

X#=Cos(angle#)*(Width*0.90)
Y#=Sin(angle#)*(Height*0.90)
SetShapevertex TempShape,VertIndex,x#,y#

; Link edges
SetShapeEdge ClockShape,VertIndex,VertIndex,VertIndex+1
SetShapeEdge TempShape,VertIndex,VertIndex,VertIndex+1

inc VertIndex
next

dec vertindex
SetShapeEdge ClockShape,VertIndex,VertIndex,1
SetShapeEdge TempShape,VertIndex,VertIndex,1

Mergeshape TempShape,ClockShape
deleteShape TempShape

ShapesCreated=1
EndIF

Lockbuffer

ink $446677
Drawshape ClockShape,cx,cy,2
ink $ff6677
Drawshape ClockShape,cx,cy,1

Local Second=CurrentSecond()
Local Minute=CurrentMinute()
Local Hour=CurrentHour()

; Minute Hand
angle#=wrapangle((360/12.0)*Hour,-90)
LInec cx,cy,cosnewvalue(cx,angle#,Width*0.5),Sinnewvalue(cy,angle#,Height*0.5),$ff0000

; Minute Hand
angle#=wrapangle((360/60.0)*minute,-90)
Linec cx,cy,cosnewvalue(cx,angle#,Width*0.75),Sinnewvalue(cy,angle#,Height*0.75),$ffffff

; Second Hand
angle#=wrapangle((360/60.0)*second,-90)
Linec cx,cy,cosnewvalue(cx,angle#,Width*0.80),Sinnewvalue(cy,angle#,Height*0.80),$888888

unlockbuffer

EndFunction