ZX 81 - BASIC Programming

Sinclair ZX Spectrum
Chapter 18.1 - Graphics
Here are some of the most elegant features of the ZX81; they use what are called pixels (picture elements). The screen you can display on has 22 lines & 32 columns, making 22*23 = 704 character positions, & each of these contains 4 pixels, divided up like a slice of Battenburg cake.

A pixel is specified by two numbers, its coordinates. The first, its x-coordinate, says how for it is across from the extreme left-hand column (remember, X is ACROSS), & the second, its y-coordinate, says how far if is up from the bottom. These coordinates are usually written as a pair in brackets, so (0,0), (63,0), (0,43) & (63,43) are the bottom left-, bottom right-, top left-, & top right-hand corners.

The statement

PLOT x-coordinate, y-coordinate

blacks in the pixel with these coordinates, while the statement

UNPLOT x-coordinate, y-coordinate

blanks it out.

Try this measles program:

10 PLOT INT (RND*64),INT (RND*44)

20 INPUT A$

30 GOTO 10

This plots a random point each time you press NEWLINE.

Here is a rather more useful program. It plots a graph of the function SIN (a sine wave) for values between 0 & 2.

10 FOR N=0 TO 63

20 PLOT N, 22+20*SIN (N/32*PI)

30 NEXT N

This next one plots a graph of SQR (part of a parabola) between 0 & 4:

10 FOR N=0 TO 63

20 PLOT N,20*SQR (N/16)

30 NEXT N

Notice that pixel coordinates are rather different from the line & column in an AT item. At the end of this chapter is a diagram which you may find useful in working out pixel coordinates & line & column numbers.

Sinclair ZX Spectrum

  Previous Page Back Next Page