This program implements an analog clock display using Sinclair BASIC graphics. It draws a clock face with a circle, numeric hour markers positioned trigonometrically, and two hands: a minute hand (length 60) and an hour hand (length 55). The second loop (lines 110–190) animates a seconds dot that sweeps around the clock face using OVER 1 (XOR plotting) to erase and redraw, accompanied by a short BEEP each tick. The subroutine at line 460 draws an additional decorative inner circle by manually plotting points at 6-degree intervals rather than using the built-in CIRCLE command, giving finer control over the dot density.
Program Analysis
Program Structure
The program is organized into a main initialization block, a main timing loop, and two subroutines:
- Lines 5–90: Initialization — draws the outer circle, calls the inner-circle subroutine, and prints the 12 hour numerals around the face.
- Lines 100–105: Draws initial hour and minute hands before the main loop starts.
- Lines 110–330: The primary animation loop — sweeps a seconds indicator dot around the face (lines 110–190), then updates the minute hand (lines 250–330).
- Lines 340–450: Subroutine to erase and redraw the hour hand, called every 12 minute-hand steps.
- Lines 460–570: Subroutine to draw an inner decorative circle by manually stepping through angles at 6-degree increments.
- Line 600: Saves the program with auto-run from line 1.
Variable Usage
| Variable | Role |
|---|---|
T | Minute counter (increments each full seconds sweep) |
U | Hour-hand step counter |
B | Hour-hand angle in radians |
A | Minute-hand angle in radians |
V | Seconds dot loop counter (0–60) |
C | Current seconds angle in radians |
SX, SY | Screen coordinates of the seconds dot |
MX, MY | Minute-hand draw offsets |
HX, HY | Hour-hand draw offsets |
xc, yc, r, d, p, x, y | Inner-circle subroutine working variables |
OVER 1 XOR Technique
The program makes extensive use of OVER 1 to achieve flicker-free erase-and-redraw. By plotting or drawing the same pixels twice with OVER 1 active, the screen pixels are XOR’d back to their original state, effectively erasing the hand or dot without clearing the clock face beneath it. This is the standard Sinclair BASIC animation idiom for moving graphics over a static background.
Trigonometric Hand Placement
All hands and markers use the standard clock-coordinate convention where 12 o’clock is “up.” Since the Spectrum’s Y axis increases upward, the formulas use SIN for the horizontal offset and COS for the vertical offset. Hour numerals are placed at line 80 using PRINT AT with 10-9*COS(N/6*PI) for row and 10+9*SIN(N/6*PI) for column, mapping the 12 positions correctly to the character grid.
Seconds Animation and Timing
The seconds indicator is a single pixel swept with PLOT and erased by re-plotting with OVER 1. Each step includes BEEP .01,25 for an audible tick and PAUSE 1 to pace the animation. With 61 iterations per sweep (V=0 to 60 inclusive due to the forced reset at V=60 in line 180), the timing is approximate rather than calibrated to real-world seconds, since BASIC execution speed and BEEP duration are not precisely one second per sweep.
Notable Anomalies and Bugs
- V=0 to 60 (61 ticks): The loop runs from 0 to 60, giving 61 positions rather than 60, so each “minute” is slightly longer than intended. The forced reset at line 180 (
IF V=60 THEN LET V=0: GO TO 200) exits the loop early on the 61st iteration, skipping theNEXT Vat line 190. - Hour hand update frequency: Line 295 triggers the hour-hand subroutine every 12 minutes (
IF T/12=INT(T/12)), giving 5 steps per hour — a coarse but functional approximation. - Inner circle subroutine (460–570): Draws a circle of radius 82 by manually iterating angles at 6-degree steps, while line 50 separately draws an outer circle of radius 85 using the built-in
CIRCLEcommand. These produce two concentric rings forming the clock border. - Initial hand position: Variables
B,U,A, andTare initialized to 0 or 1, so the clock always starts with both hands pointing to 12 regardless of real time.
Content
Image Gallery
Source Code
5 REM clock
10 LET B=0
20 LET U=0
30 LET A=0
40 LET T=1
50 CIRCLE 84,90,85
60 GO SUB 460
70 FOR N=1 TO 12
80 PRINT AT 10-9*COS (N/6*PI),10+9*SIN (N/6*PI);N
90 NEXT N
100 PLOT 84,90: DRAW 55*SIN B,55*COS B
102 LET A=T/30*PI
105 PLOT 84,90: DRAW 60*SIN A,60*COS A
110 FOR V=0 TO 60
120 LET C=V/30*PI
130 LET SX=84+62*SIN C
140 LET SY=90+62*COS C
150 OVER 1: PLOT SX,SY
160 BEEP .01,25: PAUSE 1
170 PLOT SX,SY
180 IF V=60 THEN LET V=0: GO TO 200
190 NEXT V
250 LET A=T/30*PI
260 LET MX=60*SIN A
270 LET MY=60*COS A
280 PLOT 84,90
290 OVER 1: DRAW MX,MY
295 IF T/12=INT (T/12) THEN GO SUB 340
300 LET T=T+1
310 PLOT 84,90
311 LET A=T/30*PI
312 LET MX=60*SIN A
313 LET MY=60*COS A
320 OVER 1: DRAW MX,MY
330 GO TO 110
340 LET B=U/30*PI
350 LET HX=55*SIN B
360 LET HY=55*COS B
370 PLOT 84,90
380 OVER 1: DRAW HX,HY
390 PLOT 84,90
400 LET U=U+1
410 LET B=U/30*PI
420 LET HX=55*SIN B
430 LET HY=55*COS B
440 OVER 1: DRAW HX,HY
450 RETURN
460 LET xc=84: LET yc=90
470 LET r=82
480 LET d=6
490 LET d=d*PI/180
500 FOR p=0 TO 2* PI STEP d
510 LET x=r*COS (p)
520 LET y=r*SIN (p)
530 LET x=x+xc
540 LET y=y+yc
550 PLOT x,y
560 NEXT p
570 RETURN
600 SAVE "clock" LINE 1
Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.