Chapter 8 – Starcharts (Constellation Plot)

Starmaps, display a simple starmap
Constellation Plot, entering star patterns with CHR$ CODEs
Stellar Magnitudes, plotting differing star brightnesses
Star Graphics, constructing complex shapes
Flashing Stars, two ways to make stars flash
Startrax, watch the changing shapes of the constellations over hundreds of thousands of years
Stellar Magnitude, magnitude ranges of stars.

Constellation Plot

The Starmaps program demonstrated a technique for entering star patterns directly into DIMensioned arrays via INPUT. This method is advisable if many constellations and stars are to be included. The Startrax program later in this chapter (using two constellations with few stars to PLOT), holds the star positions in a CHR$ as numerics for slicing.

This short program shows two additional methods for PLOTting star patterns using DATA and in CODE form in CHR$. In both these methods the information appears in the program listing and is easy to manipulate. See Figures 8.8 and 8.9.

Figure 8.8
Lyra PLOTted via DATA and READ


Figure 8.9
Lyra PLOTted via CODEd CHR$ (shown in display)


Method 1: DATA store
This is the conventional way to store DATA and is described adequately, if briefly, in the Spectrum Manual. DATA can only be called into use by the READ command and, once READ, can only be re-used with the RESTORE command. In this particular program the DATA is READ and immediately PLOTted and so the RESTORE command is not needed.

However, when the program STOPs (with the error message ‘integer out of range’ — this will be explained later) try restarting the program with GOTO 1. The program will not restart — an error message ‘out of data’ is displayed because the DATA was not RESTOREd. Enter RUN, and the program will do just that as this command automatically RESTORES the DATA. Thus the DATA/READ/RESTORE sequence must be given some thought especially for long programs where various DATA may be used in different orders.

In the Constellation Plot program, the DATA is in Line 40 and represents the summer star pattern of Lyra (the Harp) with six stars, each with an x and y coordinate position. This means 12 items of DATA. In addition the corners of the display are also PLOTted to indicate the scale. This is the sequence of DATA that appears as:

0, 0, 63, 43, 0, 43, 63, 0

This makes a total of 20 items of DATA. The final, 21st, item of DATA is the number of stars and corner positions to be PLOTted and this is held as the first figure in the DATA sequence (ie 10).

Line 90 READs the first item of DATA (10) and the variable c sets the length of the FOR/NEXT n loop in Line 100 for all the PLOTting. Line 100 also READs the x and y coordinates from the DATA and these are PLOTted in Line 110, each coordinate value multiplied by 4, the value of the variable called ‘scale’ (which I will explain later).

Method 2: CHR$ CODE store
This method is in many ways more elegant than a DATA/READ /RESTORE sequence and relies on the sophisticated string slicing ability of the Spectrum. It does however need care in the selection of a suitable range of CHR$ from the Spectrum CHR$ set and some confusion can occur in published listings as to which CHR$ is intended. You may need to refer to the Manual to be certain.

The ASCII character set
The Spectrum uses the ASCII character set, and any CODE between CODE 32 (blank space) and CODE 127 (copyright sign) can be used conveniently. The range of CHR$ could be extended to include the ‘chunky graphic’ set from CODE 128 to CODE 143. The ‘chunky graphic’ set, the copyright sign and CODE 96 (the ‘£’ sign) are not actually part of the ASCII set but can still be used in Spectrum programs in CODE form and printed by the ZX printer — although not necessarily by other printers.

In a star PLOTting program with a screen resolution limited to 64 horizontally and 44 vertically (a quarter of the Spectrum’s potential, as mentioned in the section on Starmaps) a maximum of 64 CODEs is sufficient for the requirements. CODE 34 — the quotation sign (“) — cannot be used within a string array so it is best to assume CODE 35 — the hash sign (#) — is the minimum useful CODE. It does however make life much easier if the upper and lower case letter CODEs are used — a total of 52 CODEs. As these can form the bulk of the string, they prove much easier to identify readily and to accept the balance of required CODEs both from between the upper and lower case letter set — CODE 91 to CODE 96 — and from above the lower case letter CODEs to CODE 127 as the ASCII hieroglyphics.

The selected CODEs which I usually use and which are demonstrated in the program are from CODE 64 (@) to CODE 127 (©) inclusive. These are converted into numeric x and y values in Lines 270 and 280 thus:

LET x = CODE a$(n) – 64
LET y = CODE a$(n+ 1) – 64

By deducting 64 from each CODE, a range of values from 0 to 64 is possible:

CHR$ @ = CODE 64 – 64 = 0 to
CHR$ @ = CODE 127 – 64 = 63

This represents the horizontal or x coordinate position. The range of CODEs for the vertical or y coordinates would be:

CHR$@ = CODE 64 – 64 = O to
CHR$k = CODE 107 – 64 = 43

From Line 200 the program demonstrates the PLOTting of the Lyra star pattern using the CODEs contained in the characters of the a$. The a$ contains 21 characters encoding precisely the same information as in the DATA of Line 40 used exclusively in the first part of the program. The only difference is that the first character of the a$, ie ‘T’, has an effective value of 20:

CHR$ T = CODE 84 – 64 = 20

and this is used in setting the length of the FOR/NEXT n loop in Line 260:

FOR n = 2 TO CODE a$(l) – 64 STEP 2
where n has a value sequentially of:

2, 4, 6, 8, 10, 12, 14, 16, 18, 20

via STEP 2 for the x coordinate value in the a$. Thus the y coordinate value is extracted by the odd numbers of the loop:

3, 5, 7, 9, 11, 13, 15, 17, 19,21

in the form… CODE a$(n+l) – 64.

Scaling the screen image
It is often useful to change the scale of the star pattern on the screen and the variable called ‘scale’ is used to do this. In the first part of the program using DATA, and before PLOTting the star positions, this variable is set to a value of 4 so enlarging the separation of the star images to fill the screen, particularly the corner markers. In this second part of the program the scale is initially set to a value of 3 and this is amended, once the FOR /NEXT n loop is completed, in Line 310:

LET scale = scale – 0.5: GOTO 230

The GOTO 230 sends the program around the FOR/NEXT n loop again and again until the program crashes with the error message ‘integer out of range’, because the scale of the image is now too large to be PLOTted on the screen.

But before it crashes the Lyra star pattern is seen to shrink in size, in progressive steps, to a single pixel in the bottom left corner of the screen before enlarging again. The current value of the scale variable is displayed at the top right of the screen and it will be noted that constantly deducting 0.5 from this variable (initially set to a value of 3) will, after six repeats of the n loop, go to negative values and increase the image size again. Thus the scale variable can have negative values as well as positive values and the PLOTted results appear similar.

Preparing starcharts
For an explanation of preparing the starcharts before transfer to a Spectrum program, refer to the Starmaps program earlier in this chapter. Let it suffice here to say that, if it is intended to use characters to CODE the star positions, then the graph paper should be marked on the x and y axes with the CHR$ rather than numeric values. Use the selection of CHR$ with CODE 64 to CODE 127 for the x axis and CODE 64 to CODE 107 for the y axis as explained above.

More constellations
This program only demonstrates how to PLOT the star pattern of Lyra — one constellation. If more constellations are to be PLOTted then here is a simple way to handle and select the DATA without entering the information into DIMensional arrays. As it is much easier to select a given constellation via CHR$ in string arrays, the explanation will be confined to this method.

The CHR$ CODEs used in Method 2 above are combined with the conditional selection, used in the Startrax program later in this chapter, from a series of constellations all similarly named — in this case a$. Thus after each constellation has been sketched on to graph paper and converted into a string of CHR$ CODEs, these are entered into the program between Line 200 to 210 as an a$. Each a$ must be followed by a conditional statement so that the program may look something like this:

201 LET a$ = “T…………..”: IF b$(1) = “A” THEN GOTO 220
202 LET a$ = “L………”: IF b$(1) = “D” THEN GOTO 220
203 LET a$ = “R………..”: IF b$(1) = “C” THEN GOTO 220
204 LET a$ = “R………..”: IF b$(2) = “u” THEN GOTO 220

The constellations supposedly represented are, in order, (A)quila (10 stars), (D)elphinus (6 stars), (C)ygnus (9 stars) and A(u)riga (9 stars). Note how the conditional GOTO in Line 204 selects the second letter, ie b$(2), as lower case V in Auriga to distinguish it from b$(l) in Aquila in Line 201. The first letter in each a$ CODEs the number of characters immediately following it, which are represented by full stops. The only program amendments are the deletion of Lines 20 to 130 inclusive and Line 310 and the addition of Line 150 (INPUT b$) to select your constellation to PLOT.

40 DATA 10, 0, 0, 63, 43, 0, 43, 63, 0, 41, 26, 39, 24, 39, 27, 35, 23, 34, 17, 37, 18
60 LET scale=4
70 PRINT “Lyra”,”scale=”;scale
90 READ c
100 FOR n=1 TO c: READ x,y
110 PLOT x*scale,y*scale
120 NEXT n
130 PAUSE 100
210 LET a$=”T@@@k@k@@iZgXg[cWbQeR”
220 LET scale=3
230 PAUSE 100: PAPER 2: CLS
240 PRINT “Lyra”,”scale=”;scale
250 PRINT “via a$ codes”
260 FOR n=2 TO CODE a$(1)-64 STEP 2
270 LET x=CODE a$(n)-64
280 LET y=CODE a$(n+1)-64
290 PLOT x*scale,y*scale
300 NEXT n
310 LET scale=scale-.5: GO TO 230

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s