Popular Computing Weekly 28/10/1982 Page 19

Spectrum Programming

In this slot various contributors explore different aspects of the ZX Spectrum

Decorative line work on the small screen

Malcolm Davison holds up a mirror to the cosmos - with impressive results.

For producing patterns on the screen, the DRAW statement has a lot to offer.
Here are a few examples:

The Tent program was carefully mapped out on a card - an enlarged version of the
one in the Sinclair manual (page 102) - before I commenced coding. Drawing a
series of lines to meet another sloping line might have presented problems in
establishing the x and y co-ordinates of their intersection. In fact, this was
very straightforward.

Consider the x axis first. If 20 lines intersect one sloping line at equal
intervals, then both the x co-ordinates of the sloping lines ends may be
subtracted and sub-divided into 20 as well, allowing you to establish the new x
co-ordinates of each intersection. This may also be done for the y co-ordinates.

The Fan which was superimposed over the tent posed and interesting problem, as
I needed equal lengths of each spoke. The DRAW statement does not allow you to
give the distance from the fixed sharing point, so I had to resort to
Pythagoras's Theorem (see line 170} to establish the x and y co-ordinates of
the furthest end of the spoke.

The fans program started like the fan in the tent program. Changing the
co-ordinates on the DRAW statement to negative instead of positive and altering
the PLOT statement to a point at the top of the screen allowed two fans to be
superimposed. Increasing the value of z by a smaller effective interference
pattern between the two fans.

Feather is another variation on the original fan - but the length of the arm is
reproduced in steps (see line 170) by c for every spoke. Peacock is a further
refinement on Feather. The plot position is moved up the y axis for each spoke
drawn - by the value of c.

The idea behind Cosmos was straightforward - to produce mirror images of the
basic fan program. However, there was much juggling with the basic plot
positions, range of values for c and length of the spoke, until a neat pattern
resulted within the bounds of the screen. But much of this was by trial and
error, altering the coding and running the program to see the effect. This idea
of mirror imaging is very useful and quite easy to do. Produce a pattern
anywhere on the screen - adjust its x and y co-ordinates to a more suitable
place - the reproduce its mirror images. By putting the PLOT and DRAW paired
statements in the correct sequence, the build up of the picture can look very
effective indeed. A partly completed pattern - by pressing the BREAK and SHIFT
keys - can be just as effective as the complete pattern.