Hi,
Just to get you started, here's some code I used for a DBC Challenge. Credit goes to NanoGamez guy for help with the angle calculation - but the rest of the code I did myself.
Others might have done this a little differently, but this works.
Anyway, paste this into DBC and see if you can learn from it
rem Basic Analogue Clock
rem Steve Paul Thomas, November 2008
rem Manual refresh
sync on
rem Hide the default mouse pointer
hide mouse
rem Easily configurable colours of stuff...
rem If you dont like the default sidebar colour then you
rem can change it here (default is a blue-grey colour)
sidebar = rgb(100,100,180)
rem Colour of the hour hand and the hour blocks on the clock
rem Default is red
hourcolour = rgb(255,0,0)
rem Colour of the minute hand and minute blocks on the clock
rem Default is yellow
minutecolour = rgb(255,255,0)
rem Colour of the second hand on the clock
rem Default is grey
secondcolour = rgb(60,60,60)
rem Create an offscreen drawing area
create bitmap 1,640,480
cls 0
rem Set the program up
gosub _make_clock_sprite
rem Main Program Loop ----------------------------
do
rem Clear the screen with black
cls 0
rem Clock box sprite - position me where you want!
sprite 2,320,240,2
if mytime$ <> get time$() then gosub _make_clock_sprite
sync
loop
rem End Main Program Loop ----------------------------
` (((((((((((((((((((( S U B R O U T I N E S ))))))))))))))))))))))))))
remstart
This creates an analogue clock with digital
time underneath it.
Credit to NanoGamez guy for explaining
how to calculate the angle on the fly, rather than use
a huge list of angles for every hour, minute and second.
remend
_make_clock_sprite:
rem Assign DB time to mytime variable
mytime$ = get time$()
set current bitmap 1
rem Clear the screen with the sidebar colour
cls sidebar
rem This bunch of code puts yellow blocks at 6degree
rem points around the face, then you get one block for
rem each minute of the clock face
minutesradius = 50
minutesangle# = 0.0
minutes_step# = 6.0
rem Switch to minutecolour pen
ink minutecolour,0
rem Draw the minute blocks
for i = 0 to 60
minutesx = minutesradius * cos(minutesangle#)
minutesy = minutesradius * sin(minutesangle#)
box (minutesx + 320)-1,(minutesy + 240)-1,minutesx+320+2,minutesy+240+2
minutesangle# = wrapvalue(minutesangle# + minutes_step#)
next i
rem End of minute block drawing
rem Extract the minute from mytime
myminute$ = mid$(mytime$,4)
myminute$ = myminute$ + mid$(mytime$,5)
rem The angle of a minute is: (minute / 60) * 360 -90
anglem = (((val(myminute$) / 60) * 360) -90)
line 320,240,(40 * cos(anglem))+320,(40 * sin(anglem))+240
rem Switch to secondhand pen
ink secondcolour,0
rem Extract the seconds from mytime
myseconds$ = right$(mytime$,2)
rem The angle of a second is: (second / 60) * 360 -90
angles = (((val(myseconds$) / 60) * 360) -90)
line 320,240,(40 * cos(angles))+320,(40 * sin(angles))+240
rem This bunch of code puts red blocks at 30 degree
rem points around the face, then you get one block for
rem each hour of the clock face
hoursradius = 50
hoursangle# = 0.0
hours_step# = 30.0
rem Switch to hourhand pen
ink hourcolour,0
for i = 1 to 12
hoursx = hoursradius * cos(hoursangle#)
hoursy = hoursradius * sin(hoursangle#)
box (hoursx + 320)-1,(hoursy + 240)-1,hoursx+320+2,hoursy+240+2
hoursangle# = wrapvalue(hoursangle# + hours_step#)
next i
rem End of block drawing
rem Extract the hour from mytime
myhours$ = left$(mytime$,2)
rem The angle of an hour is: (hour / 12) * 360 -90
angleh = (((val(myhours$) / 12) * 360) -90)
rem Just to add some inbetweening
rem If its quarter past the hour to just before half past
if (val(myminute$) >= 15) and (val(myminute$) < 30)
angleh = wrapvalue(angleh +6)
endif
rem If its half past the hour to just before quarter to
if (val(myminute$) >= 30) and (val(myminute$) < 45)
angleh = wrapvalue(angleh +12)
endif
rem If its quarter to the hour to just before hour
if (val(myminute$) >= 45) and (val(myminute$) <= 59)
angleh = wrapvalue(angleh +18)
endif
rem Draw hour hand
line 320,240,(30 * cos(angleh))+320,(30 * sin(angleh))+240
rem Set pen colour to white and draw a big circle for the clock face
ink rgb(255,255,255),0
clockradius = 55
clockangle# = 0.0
clock_step# = 1.0
rem Draw outer circle of clock face
for i = 0 to 360
clockx = clockradius * cos(clockangle#)
clocky = clockradius * sin(clockangle#)
box (clockx + 320)-1,(clocky + 240)-1,clockx+320+2,clocky+240+2
clockangle# = wrapvalue(clockangle# + clock_step#)
next i
rem End of block drawing
rem Draw a border...
rem Right and top in white
ink rgb(255,255,255),0
line 384,320,384,180
line 384,180,256,180
rem Set pen to white
ink rgb(255,255,255),0
set text font "arial"
set text size 10
rem Write out the full time in digital form
center text 320,300,mytime$
rem Capture the image and place in image slot 2
get image 2,256,180,384,320
rem Switch canvas back to the screen
set current bitmap 0
rem Return to Main Program Loop
return