Skip to content

Make it move

Compare leaving a trail with erasing a marker as its position changes.

Movement is a sequence of pictures. We’ll draw at successive columns and compare keeping the old picture with erasing it.

Continue with Put it somewhere, or enter the first complete listing into an empty program. Keep your hands off the keys while watching a run so that key presses do not shorten its pauses.

Leave a trail

Replace line 50, delete 56, and add 57, 58, 70 and 90:

10 PAPER 0
20 INK 7
30 BORDER 0
40 CLS
50 PRINT "WATCH THE MARKER"
55 LET row=10
57 FOR c=1 TO 30
58 LET col=c
60 PRINT AT row,col;"O"
70 PAUSE 5
90 NEXT c

FOR c=1 TO 30 visits columns 1 through 30. The loop variable must be one letter in Sinclair BASIC; c controls repetition, and line 58 copies its value into our position variable col. Each visit draws the O and waits five display frames before NEXT c advances to the next column.

Enter FOR with F, TO with left Option/Alt+F, NEXT with N and PAUSE with M after a line number. Give the answer a rhythm explains the counted loop and pause in a smaller example.

Run it. A row of O characters grows across the screen. Changing col has not erased what was drawn at its old value. That trail is useful evidence of every position visited, but it does not look like one object moving.

A line of O characters records the columns already visited.
The first version leaves each earlier position visible.

Remove the old picture

Add line 80:

10 PAPER 0
20 INK 7
30 BORDER 0
40 CLS
50 PRINT "WATCH THE MARKER"
55 LET row=10
57 FOR c=1 TO 30
58 LET col=c
60 PRINT AT row,col;"O"
70 PAUSE 5
80 PRINT AT row,col;" "
90 NEXT c

This prints a quoted space, not an empty string, at the current position. The space paints that cell with the paper colour. The order is now draw, wait, erase, advance. Every iteration removes its own marker before the next one is drawn.

Watch the whole run. One O travels across the row; at the end, none remains. The last iteration erased column 30 too. A final screenshot alone would miss the movement, so compare what happens between the start and the ending.

On this plain background, a space restores the cell. Over a patterned wall or another object, erasing with a space would destroy part of the scene. A game with such a background would need to restore the background’s actual content.

One O remains visible during the version that erases each old position.
With erasing, one marker travels across the row.

Let it settle at the edge

Replace line 57 so the loop ends at 29, and add line 95:

10 PAPER 0
20 INK 7
30 BORDER 0
40 CLS
50 PRINT "WATCH THE MARKER"
55 LET row=10
57 FOR c=1 TO 29
58 LET col=c
60 PRINT AT row,col;"O"
70 PAUSE 5
80 PRINT AT row,col;" "
90 NEXT c
95 PRINT AT row,30;"O"

The loop now animates columns 1–29. When it finishes, line 95 draws one final O at column 30 and leaves it there. The program ends normally; RUN clears the screen and starts another journey.

The marker finishes at column 30 and remains visible after the program ends.
The marker finishes at column 30 and remains visible after the program ends.

Try PAUSE 2, then PAUSE 10, in line 70. Compare the pace and restore 5. The interval includes drawing, erasing and BASIC’s other work as well as the pause. A pressed key can interrupt PAUSE, so this is not a fixed-speed promise.

Why not clear the whole screen on every step?

It would remove the instructions as well as the old marker, and require drawing them again. We know which one cell changed. Updating that cell keeps the rest of the picture and avoids unnecessary work.

Foundations: Doing It Again offers another trace of counted repetition. Here each visit produces a small visual change; the next lesson will let the player decide which change to request.

Next, Let the player steer continues this program.

Sources

Steven Vickers, edited by Robin Bradbeer, ZX Spectrum BASIC Programming, second edition (Sinclair Research, 1983), chapter 4 for FOR and NEXT; chapters 15 and 18 for positioned output, motion and PAUSE.