' This program exported from BASIC Anywhere Machine (Version [5.2.3].[2024.09.09.00.00]) on 2025.11.16 at 03:16 (Coordinated Universal Time)
_TITLE "Rolling Clock"
' This program was written by Charlie Veniot


' 🔶🔶🔶 Declarations

' For each digit (0 to 9), get the "8x8 pixel map"
  DIM da$( 0 TO 9 )
  FOR i = 0 TO 9
      LET da$(i) = GETCHR$( 48 + i )
  NEXT i

' For splitting current time into components
' The t$ array has each component of the time, including the colons
' The td% array indicates the position of the digits (the only components of the time we need to actually process)
  DIM t$(1 TO 8)
  CONST td%(1 TO 6) = {1,2,4,5,7,8}

' Vertical mid position of screen, were main part of clock displays
  DIM ymid% = 8

' 🔶🔶🔶 Main Program

  SCREEN _NEWIMAGE(73, ymid% * 3, 0)
  COLOR 1,0
  CLS
  LINE (19, 0) TO (26,ymid% + 15), 0, BF
  LINE (46, 0) TO (53,ymid% + 15), 0, BF
  FOR i = 0 TO 72 STEP 9
      LINE (i, ymid%) TO (i,ymid% + 7), 7
  NEXT i
  GOSUB D100_✏DisplayTheColons

  🡆EndlessLoop:
    GOSUB G_⏲GetPartsOfCurrentTime
    GOSUB D200_✏DisplayTheDigits
    SLEEP 0.1
    GOTO 🡆EndlessLoop

  END

' 🔶🔶🔶 GOSUB Routines

D100_✏DisplayTheColons:
  FOR i = 0 TO 1
      LET c$ = GETCHR$( ASC(":") )
      FOR x = 0 TO 7 : FOR y = 0 TO 7
          PSET( x + 19 + i * 27, y + ymid% ), IFF( MID$(c$, x + y * 8 + 1, 1) = "X", 0, 15 )
      NEXT y, x
  NEXT i
  RETURN
  
D200_✏DisplayTheDigits:
  fgc% = 0
  FOR i = 1 TO 6
      GOSUB S_✍SetModMax
      
      bkc% = 15
    ' current digit for "i" part of time
      temp% = VAL( t$( td%(i) ) )
      d$ = da$( temp% ) 
      IF temp% = modmax% - 1 THEN fgc% = 4 ELSE fgc% = 0
      yadj = 0  : GOSUB P_🎯PutChar
      fgc% = 0
      
      bkc% = 8
    ' next digit for "i" part of time
      d$ = da$( [ VAL( t$( td%(i) ) ) + 1 ] MOD modmax% ) 
      yadj = -8 : GOSUB P_🎯PutChar
      
    ' previous digit for "i" part of time
      v% = VAL( t$( td%(i) ) - 1 )
      d$ = da$( IFF(v% = -1, modmax% - 1, v% ) )
      yadj = +8 : GOSUB P_🎯PutChar
  NEXT i
  RETURN

G_⏲GetPartsOfCurrentTime:
  FOR i = 1 TO 8
      t$(i) = MID$( TIME$, i, 1)
''      t$(i) = MID$( "21:00:03", i, 1)
  NEXT i
  RETURN

P_🎯PutChar:
  FOR x = 0 TO 7 : FOR y = 0 TO 7
      PSET( x + 1 * [ [ td%( i ) ] ]  + [ [ td%( i ) - 1 ] * 8 ], y + ymid% + yadj ), IFF( MID$( d$, x + y * 8 + 1, 1) = "X", fgc%, bkc% )
  NEXT y, x
  RETURN

S_✍SetModMax:
    SELECT CASE i
      CASE 4, 6
        modmax% = 10
      CASE 3, 5
        modmax% = 6
      CASE 2
        temp% = VAL( t$(1) + t$(2) )
        IF temp% < 20 THEN modmax% = 10 ELSE modmax% = 4
      CASE 1
        modmax% = 3
    END SELECT
RETURN