Popular Computing Weekly 21/10/1982 Page 20

Spectrum Programming

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

Line-up on shady characters

Malcolm Davison explains how to construct 3D cones and cylinders.

Having established how to draw an ellipse (Popular Computing Weekly, October
7), this article paves the way to constructing 3D representations of cones and
cylinders, and introduces the idea of 'shading' to give the illusion of
solidity.

To draw the cylinder, I first planned the drawing on graph paper marked with
the plot and print positions. The lengths and positions of the major and minor
axes can be quickly be ascertained and the lengths of the lines between them.

Coding was straightforward, see 'cylinder'. Lines 60-140 and 400-510 draw the
outline of the ellipse, while lines 795-812 draw a series of lines of the same
length from different plot positions. The second half of the PLOT statements in
lines 400, 410, 500 and 510 are repeated for the DRAW statements.

'Cylinder 2' is the same as 'cylinder' up to line 520, but adds a shading
routine and draws the right-hand edge of the cylinder. The shading effect is
produced by plotting the circumference of an ellipse, but reducing the
frequency of the plotting points (lines 795 and 796), and then using these
points as the starting position for a DRAW statement. Line 794 draws the top
line on the cylinder.

Cylinder development

The 'cone' is a development of the cylinder. Lines 1-530 draw the ellipse and
lines 620-637 draw the left-hand lines to the tip of the cone. Lines 650-690
draw the lines to the extremities of the ellipse.

'Pattern 1' starts as a straightforward plot of an ellipse. the value of the
major axis (m) is increased during each loop. While the count 'a' in line 90 is
sufficient for the first full circumference of the ellipse, as 'm' increases it
falls  short of subsequent loops. As a result, it produces curves to the left
and right of the ellipse.

'Pattern 2' is the result of repeatedly plotting and ellipse further along the
x axes. The program runs for about three-quarters of an hour. If you want a
record of it, store it on tape using SAVE "Pattern 2" SCREEN$.

If you want to intermediate printout just press the SHIFT and BREAK keys,
followed by COPY. After the printout is complete, press CONTINUE. If at any
time you want to know how far the program has got -- break into the program and
type LPRINT j, which will print the value of the loop count (1 to 50) onto the
printer an so will not affect the display. Then press CONTINUE.