Chapter 16 – Graphics

In this chapter, we shall see how to draw pictures on your ZX Spectrum Next's screen. As we learned in Chapters 14 and 15, Layer 0 can only use 175 pixels out of its maximum 192 pixel vertical resolution while the other layers accept the maximum height defined by the layer as their vertical resolution. Moreover, if you recall Fig. 9 and 10, Layer 0 has a different graphics coordinate origin from the rest of the layers/modes located at the bottom leftmost of the screen instead of the top leftmost. All basic graphics commands that we will explore (PLOT, DRAW, CIRCLE and POINT) accept both coordinate origins while the LAYER and TILE commands (as well as the SPRITE command we'll explore in the following chapter) accept only the top leftmost corner as the coordinate origin. The side-effect of these inverted coordinate systems is that most graphics you will program will appear inverted on the y-axis if you do not account for that difference. We'll illustrate this fact shortly.

PLOT

The statement:

PLOT x_coordinate, y_coordinate

inks in the pixel with these coordinates, so this measly program:

10 PLOT INT(RND*128), INT
   (RND*96):INPUT a$: GO TO 10

plots a random point each time you press ENTER. This will work on all layers1, although it will not use the entire area of the screen in all modes. Can you figure out why?

Here is a rather more interesting program. It plots a graph of the function SIN (a sine wave) for values between 0 and 2π:

10 FOR n=0 TO 255: REM change
   to 127 for LoRes
20 PLOT n,88+80*SIN(n/128*PI)
30 NEXT n

This next program plots a graph of SQR (part of a parabola) between 0 and 4:

10 FOR n=0 TO 255
20 PLOT n,80*SQR (n/64)
30 NEXT n

Notice that when in Layer 0, pixel coordinates are rather different from the line and column in an AT item. You may find the diagrams in Chapter 14 useful when working out pixel coordinates and line and column numbers for Layer 0. The other layers as we've already discussed are pretty straightforward. To illustrate, switch to HiRes and try again. What you see when entering:

 5 LAYER 1,2
10 FOR n=0 TO 255
20 PLOT n,80*SQR (n/64)
30 NEXT n

and run the program is exactly what we were talking about earlier. Our graph, has changed both orientation and stops at the middle of the screen's width. To make the out-

1 All layers, EXCEPT Layer 3 and the High Res versions of Layer 2 as they're not directly supported by NextBASIC.


ZX Spectrum Next User Manual, 3rd Edition (ISBN 978-1-5272-5496-1), written and illustrated by Phoebus R. Dokos. Copyright © 2020-2024 Phoebus Dokos / SpecNext Ltd. Licensed under CC BY-NC-SA 4.0. This is a transcription and can contain errors; check any doubt against the printed page.