Rainbow Clock
Joel Swank
Rockaway, OR
A short program to make the VIC screen a digital clock with rapidly changing background and border colors.
This program turns VIC into a rainbow digital clock. It's simple, but it demonstrates many of VIC's features. The time is displayed in the center of the screen every second. A tick-tock is sounded in the TV speaker. Every second the random number generator is used to generate a new background/border combination. Between seconds, a random color is POKEd into a random spot on the screen.
The area of the screen around the time is protected from this. The color of the time itself rotates through the eight VIC colors. You might notice that occasionally the time disappears. This happens when the color of the time happens to match the screen color. It never disappears for a whole second.
Rainbow clock used VIC's internal clock to keep the time. Each time you turn on VIC, you must set the clock to the current time. The time is kept in the special BASIC variable TI$. The time is a string of six decimal digits representing hours, minutes, and seconds. This variable is automatically updated every second by VIC. To set the time, just assign a string of six digits to TI$. The time must be entered in 24-hour format and all six digits must be entered. For example: TI$ = "060000" for 6 a.m. and TI$ = "180000" for 6 p.m. Rainbow clock converts the time back to 12-hour format. VIC's internal clock is fairly accurate. I tested mine for 24 hours, and it gained about two seconds. Once you have set the time, any BASIC program can get the current time from TI$.
40 S1$ = " " 50 L = 1 60 L$ = "{BLK} {WHT} {RED} {CYN} {PUR} {GRN} {BLU} {YEL} " 70 C$ = " {BLK} " 80 PRINT " {CLEAR} " ; 90 T = 36874 : T1 = 1 100 POKE36878, 15 110 H$ = MID$ (TI$, 1, 2) 120 H = VAL (H$) 130 IFH<12THENP$ = "AM" 140 IFH>12THENP$ = "PM" 150 M$ = MID$ (TI$, 3, 2) 160 S$ = MID$ (TI$, 5, 2) 170 IFH>12THENH = H-12 180 IFH = 0THENH = 12 190 H$ = MID$ (STR$ (H), 2, 2) 200 IFLEN(H$) <2THENH$ = " " + H$ 210 PRINTC$; " {HOME} {10 DOWN} {08 RIGHT}" ; H$; " : " ; M$; " : "; S$; 220 PRINT " {03 DOWN} {05 LEFT} " ; P$; 230 M = INT (RND(1)*506) 240 IFM>204ANDM<215THEN230 250 IFM>226ANDM<237THEN230 260 IFM>248ANDM<259THEN230 270 N = INT(RND(1)*7)+1 280 J = 160 290 IFRND(1)<.15 THENJ=32 300 POKE7680+M, J 310 POKE38400+M, N 320 GETQ$ : IFQ$ = " " THEN 340 330 GETQ$ : IFQ$ = " " THEN 330 340 IFS1$ = S$GOTO110 350 POKE T, 200 360 S1$ = S$ 370 C$ = MID$ (L$, L, 1) 380 L = L + 1 390 IFL>7THENL = 1 400 BS = INT(RND(1) * 15) * 16 + 8 + INT(RND(1) * 7) 410 POKE36879, BS 420 POKET, 0 430 T = T + T1 440 T1 = -T1 450 GOTO110