set display mode 1280, 1024, 32
set text font "Arial"
set text size 72
#constant imageSize 64
 
for i = 0 to 9
   cls
   s$ = str$(i)
   text (imageSize-text width(s$))*0.5, (imageSize-text height(s$))*0.5, s$
   get image i+1, 0, 0, imageSize, imageSize
next i
 
`and the colon
cls
s$ = ":"
text (imageSize-text width(s$))*0.5, (imageSize-text height(s$))*0.5, s$
get image 12, 0, 0, imageSize, imageSize
cls
 
 
 
`Setup the image holders
for i = 1 to 8
   make object plain i, 1, 1
   position object i, (i-4.5), 0, 0
   point object i, (i-4.5), 0, -1
   `texture object i, i
   set object light i, 0
   set object transparency i,1
   offset limb i, 0, 0, 0.5, 0
next i
 
 
`Some arrays
Dim itemChanged(8)
Dim itemAngle#(8)
Dim timeArray(8)
Dim displayArray(8)
 
`set the default time to 0 but set it so that they're all set to update on the first "tick"
parseTime()
for i = 1 to 8
   texture object i, 1
   displayArray(i) = timeArray(i)
   itemChanged(i) = 1
next i
 
 
`initialise the display setup
sync on
sync rate 0
randomize timer()
color backdrop 0
backdrop off
 
 
`camera swing
a# = 0.0
b# = 0.0
#constant DIST -12
#constant SWAY_RADIUS 3
#constant ARC_SIZE 20
autocam off
 
position camera SWAY_RADIUS, 0, BOON
point camera 0, 0, 0
 
 
 
frameTime# = 1.0
startTime = timer()
do
   frameTime# = (frameTime# * 0.8) + ((timer() - startTime) * 0.2)
   startTime = timer()
   parseTime()
   for i = 1 to 8
      `if the current time is different to the displayed time then something has changed to we better update it...
      if timeArray(i) <> displayArray(i)
         `set us to phase 1
         itemChanged(i) = 1
         `display the new time item
         displayArray(i) = timeArray(i)
      endif
 
      if itemChanged(i) > 0
         `The item has just changed - better change it!!
         inc itemAngle#(i), frameTime# * 0.400
         xrotate object i, sin(itemAngle#(i)) * -90.0
         set alpha mapping on i, 100 - (sin(itemAngle#(i))*100)
 
         `check the angles
         if itemAngle#(i) >= 180
            `If we've done a full sin arc, make sure the digit is reset to 0 degree's.
            xrotate object i, 0
            `reset its status
            itemChanged(i)=0
            `and its stored angle
            itemAngle#(i) = 0.0
            `and its transparency
            set alpha mapping on i, 100
         else
            `We haven't finished yet, lets see if we've gone past flat (90)
            if itemAngle#(i) >= 90
               `Yup, we're past flat.. ok, are we still in "phase 1" (ie, going down)
               if itemChanged(i) = 1
                  `Yup, ok - you may now change the texture
                  texture object i, displayArray(i)+1
                  `And set us to phase 2
                  itemChanged(i) = 2
               endif
            endif
         endif
      endif
   next i
 
 
   `Camera stuff
   inc a#, frameTime# * 0.045
   inc b#, frameTime# * 0.032
   `sin(a#) produces a value between -1.0 and +1.0 in the "shape" of a sine curve.
   `  This is then scaled to produce a nice "swaying value.
   `  Cos does the same but the result is offset by quarter a wavelength.
   `  That means when sin it high, cos is 0...
   position camera SWAY_RADIUS * sin(a#), SWAY_RADIUS * cos(a#), DIST
   `point camera 0,0,0
   yrotate camera sin(b#)*ARC_SIZE
 
   sync
loop
end
 
 
function parseTime()
   t$ = get time$()
   timeArray(1) = val(mid$(t$, 1)) :`H
   timeArray(2) = val(mid$(t$, 2)) :`H
   timeArray(3) = 11 :`:
   timeArray(4) = val(mid$(t$, 4)) :`M
   timeArray(5) = val(mid$(t$, 5)) :`M
   timeArray(6) = 11 :`:
   timeArray(7) = val(mid$(t$, 7)) :`S
   timeArray(8) = val(mid$(t$, 8)) :`S
endfunction