--- title: "Clock 2" id: 57287 type: "computer_media" slug: "clock-2-2" url: "http://localhost/computer_media/clock-2-2/" markdown_url: "http://localhost/computer_media/clock-2-2.md" published_at: "2024-10-04T08:07:57+00:00" modified_at: "2026-03-30T21:18:36+00:00" author: "David Anderson" featured_image: url: "http://localhost/wp-content/uploads/2024/10/175_Clk2.png" excerpt: "A one-pixel seconds hand sweeps a trigonometrically drawn clock face, using PLOT, UNPLOT, and a timed PAUSE to animate 1000 seconds of ticking." category: - name: "Archived Media" slug: "archived-media" taxonomy: "category" url: "http://localhost/category/archived-media/" post_tag: - name: "Downloadable" slug: "downloadable" taxonomy: "post_tag" url: "http://localhost/tag/downloadable/" - name: "TS 1000" slug: "ts1000" taxonomy: "post_tag" url: "http://localhost/tag/ts1000/" model: - name: "Timex/Sinclair 1000" slug: "ts-1000" taxonomy: "model" url: "http://localhost/model/ts-1000/" genre: - name: "Home" slug: "home" taxonomy: "genre" url: "http://localhost/type/home/" media_contents: - id: 56734 title: "Timex Sinclair Public Domain Library Tape 1003" type: "computer_media" url: "http://localhost/computer_media/timex-sinclair-public-domain-library-tape-1003/" media_type: "Program" mediadate: "198x" images: - url: "http://localhost/wp-content/uploads/2024/10/175_Clk2.png" media_type_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: | Variable | Formula | Role | | --- | --- | --- | | `A` | `T/30*PI` | Angle in radians for elapsed seconds (full circle in 60 s) | | `SX` | `21+18*SIN A` | Horizontal pixel coordinate of hand tip | | `SY` | `22+18*COS A` | Vertical 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. ## 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 ```