Clock 2

This file is part of Timex Sinclair Public Domain Library Tape 1003 . Download the collection to get this file.
Date: 198x
Type: Program
Platform(s): TS 1000
Tags: Home

This program draws an analogue clock face on screen, first printing the hour numerals 1–12 around a circle using PRINT AT with trigonometric positioning, then animating a single seconds hand using PLOT and UNPLOT. The hand is drawn at pixel coordinates calculated from sine and cosine of the elapsed-second angle, then erased after a PAUSE 42 delay (approximately one second on a ZX81 at 3.25 MHz). The loop runs for 1000 seconds before halting. Because only a single point is plotted rather than a line, the “hand” is represented by one pixel at the tip of the sweep radius.


Program Analysis

Program Structure

The program divides cleanly into two phases, flagged by REM comments:

  1. Clock face drawing (lines 10–30): A FOR loop prints the numerals 1–12 around a circle using PRINT AT.
  2. Hand animation (lines 40–400): A second FOR loop over variable T (0–1000 seconds) computes the hand tip position, PLOTs it, pauses, then UNPLOTs it before advancing.

Clock Face Rendering

Hour numerals are positioned with:

  • PRINT AT 10-10*COS (N/6*PI), 10+10*SIN (N/6*PI); N

The ZX81 PRINT AT row/column origin is top-left, so cosine is subtracted from the row base to move upward, and sine is added to the column base to move rightward. The radius of 10 character cells gives a reasonable spread across the 32-column, 22-row display. N/6*PI converts the hour number into radians (1 hour = π/6 radians), matching standard clock geometry.

Seconds Hand Animation

The hand tip pixel is computed each iteration:

VariableFormulaRole
AT/30*PIAngle in radians for elapsed seconds (full circle in 60 s)
SX21+18*SIN AHorizontal pixel coordinate of hand tip
SY22+18*COS AVertical pixel coordinate of hand tip

The ZX81 pixel grid is 64×48. A centre of (21, 22) and radius of 18 pixels keeps the hand within the upper-left quadrant of the display, roughly centred on the drawn clock face. Cosine is used for the vertical axis so that the hand starts pointing upward (12 o’clock) at T=0.

Timing Mechanism

PAUSE 42 is used to approximate a one-second delay. On a ZX81 the PAUSE unit is 1/50 s (one TV frame at 50 Hz), so PAUSE 50 would be exactly one second. PAUSE 42 gives approximately 0.84 s per tick, meaning the clock runs about 16% fast. This is a common calibration compromise to partially compensate for the time taken by the PLOT, UNPLOT, and arithmetic operations in each loop iteration.

Notable Techniques

  • PLOT/UNPLOT erase cycle: Rather than redrawing the entire screen each frame, only the single hand-tip pixel is toggled, avoiding flicker and keeping the static numerals intact.
  • Single-pixel hand: Only the outermost tip of the sweep radius is drawn; no line is traced from the centre, so the visual effect is a single orbiting dot rather than a true clock hand.
  • Loop bound of 1000: The animation runs for exactly 1000 iterations (roughly 14–16 minutes at the chosen PAUSE value) before STOP is reached.

Bugs and Anomalies

  • The clock face numerals are positioned on a 10-character-cell radius centered at row 10, column 10 in character coordinates, while the hand tip uses pixel coordinates centered at (21, 22) with radius 18. These two coordinate systems are not precisely aligned, so the hand tip does not accurately track around the printed numerals.
  • PAUSE 42 produces a fast clock; PAUSE 50 (or tuning to account for loop overhead) would be more accurate.
  • Lines 420 (SAVE) and 430 (RUN) are unreachable after STOP at line 410 during normal execution.

Content

Appears On

Assembled by Tim Ward from many sources. Contains programs 10122 – 10175.

Related Products

Related Articles

Related Content

Image Gallery

Clock 2

Source Code

   1 REM "CLOCK2"
   5 REM FRST WE DRAW THE CLOCK
  10 FOR N=1 TO 12
  20 PRINT AT 10-10*COS (N/6*PI),10+10*SIN (N/6*PI);N
  30 NEXT N
  35 REM NOW WE START THE CLOCK
  40 FOR T=0 TO 1000
  45 REM T IS THE TIME IN SECONDS
  50 LET A=T/30*PI
  60 LET SX=21+18*SIN A
  70 LET SY=22+18*COS A
 200 PLOT SX,SY
 210 PAUSE 42
 310 UNPLOT SX,SY
 400 NEXT T
 410 STOP 
 420 SAVE "1017%5"
 430 RUN 

Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.

People

No people associated with this content.

Scroll to Top