--- title: "Sine Wave" id: 69519 type: "computer_media" slug: "sine-wave-2" url: "http://localhost/computer_media/sine-wave-2/" markdown_url: "http://localhost/computer_media/sine-wave-2.md" published_at: "2026-04-13T23:29:20+00:00" modified_at: "2026-04-13T23:30:25+00:00" author: "David Anderson" featured_image: url: "http://localhost/wp-content/uploads/2026/04/SCR-20260413-qzjr.png" excerpt: "Watch a sine wave build point by point across the screen, with live readouts of the x and y values updating at each step." 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 2068" slug: "ts2068" taxonomy: "post_tag" url: "http://localhost/tag/ts2068/" model: - name: "Timex/Sinclair 2068" slug: "ts-2068" taxonomy: "model" url: "http://localhost/model/ts-2068/" indiv: - name: "Ted Pozyski" slug: "ted-pozyski" taxonomy: "indiv" url: "http://localhost/indiv/ted-pozyski/" genre: - name: "Demo" slug: "demo" taxonomy: "genre" url: "http://localhost/type/demo/" media_type: "Program" programmers: - name: "Ted Pozyski" slug: "ted-pozyski" taxonomy: "indiv" url: "http://localhost/indiv/ted-pozyski/" download_url: "https://archive.org/download/timex-sinclair-software-archive/Sine%20Wave%20%281984%29%28Pozyski%2C%20Ted%29%28TS2068%29%28US%29%28Program%29.zip" mediadate: "1984" images: - url: "http://localhost/wp-content/uploads/2026/04/SCR-20260413-qzjr.png" article_media: - id: 46111 title: "Sine Wave" type: "article" url: "http://localhost/article/sine-wave/" media_type_tags: "Demo" --- # Sine Wave This program draws a sine wave on screen using PLOT commands, cycling through 63 x-positions (0 to 62) and computing y values with the formula 20+20*SIN(x/31*PI), which maps one full period of the sine function across the display width. The program first draws reference axes using PLOT and DRAW before entering the plotting loop. At each step, the current x value (scaled to degrees 0–360) and the computed y value (offset removed) are displayed in the lower portion of the screen using PRINT AT. The loop pauses at each point until the ENTER key is released, providing a step-through animation effect via the INKEY$ check at line 100. *** ## Program Analysis ### Program Structure The program is short and linear, consisting of an initialization phase (lines 20–30), a display label (line 50), and a single `FOR` loop (lines 40–110) that plots the sine wave one point at a time. There is no subroutine structure; all logic is inline within the loop. 1. **Lines 20–30:** Draw the x-axis (horizontal line at y=21, length 63) and y-axis (vertical line at x=0, height 43). 2. **Lines 40–110:** Main loop over `x` = 0 to 62, computing and plotting each sine value. 3. **Lines 50–80:** Inside the loop, three `PRINT AT` statements display the equation label, the current x in degrees, and the current y value. 4. **Line 90:**`PLOT x,y` places the pixel on screen. 5. **Line 100:** Busy-waits while ENTER is held down, then continues on release. ### Mathematics and Coordinate Mapping The sine formula at line 70 is `y = 20 + 20*SIN(x/31*PI)`. Dividing `x` (range 0–62) by 31 gives a range of 0 to 2, and multiplying by PI yields 0 to 2π — exactly one full sine period. The vertical offset of 20 shifts the wave center upward in screen coordinates, while the amplitude of 20 pixels keeps the wave within bounds. The display readout at line 80 subtracts the 20 offset to show the true mathematical y value to the user. The x-axis degree display at line 60 scales `x*360/62`, correctly mapping the loop range to 0°–360° for human-readable output. ### Key BASIC Idioms and Techniques - **Step-through animation:** Line 100 uses `IF INKEY$=CHR$ 13 THEN GO TO 100` to hold execution while ENTER is pressed. This is the inverse of the usual “wait for keypress” pattern — it waits for the key to be *released* (or not pressed), so the loop only advances when ENTER is not held. In practice, if the user never presses ENTER, the loop runs continuously without pause. - **`PRINT AT` overdraw:** The label, x, and y values are reprinted at fixed screen positions each iteration, effectively updating in place without clearing the screen. - **Axis drawing:** Using `PLOT`/`DRAW` for the axes before entering the loop is clean and efficient, ensuring the reference lines are drawn once. ### Potential Anomalies The axis at line 20 draws a horizontal line at y=21 from x=0 for 63 pixels, and the vertical axis at line 30 rises from y=0 for 43 pixels. The sine wave is plotted with y values in the range 0–40 (since the offset is 20 and amplitude is 20), so the wave fits within the vertical axis length. However, the horizontal axis at y=21 bisects the wave’s center (y=20) only approximately — the axis sits one pixel above center. This is a minor cosmetic offset rather than a functional bug. The `PRINT AT 18,10` label at line 50 is inside the loop and reprints the same string every iteration, which is redundant but harmless. Moving it before the loop would be a minor optimization. ### Variable Summary | Variable | Purpose | | --- | --- | | `x` | Loop counter, also the screen x-coordinate (0–62) | | `y` | Computed screen y-coordinate, range approximately 0–40 | ## Source Code ``` 10 REM >> Sine Wave << by Ted Pozyski \* Sync, M/A 1984 20 PLOT 0,21: DRAW 63,0 30 PLOT 0,0: DRAW 0,43 40 FOR x=0 TO 62 50 PRINT AT 18,10;"Y= 20 SINE X" 60 PRINT AT 20,10;"X= ";x*360/62 70 LET y=20+20*SIN (x/31*PI) 80 PRINT AT 21,10;"Y= ";y-20 90 PLOT x,y 100 IF INKEY$=CHR$ 13 THEN GO TO 100 110 NEXT x ```