Chapter 9 – Further Programs (Star Tester)

The Messier List, check out the fake comets
Telescope, the facts about telescopes, binoculars, cameras and astronomy
Star Tester, a quiz
Ellipses, various ellipses
Spectrum World Map, a map of the world in CHR$ CODE.

Star Tester

This is a short demonstration program to show how a simple quiz, using questions and answers, can be set up. Obviously, the quiz does not have to relate to astronomy, but it does for the purposes of this book. The program as it stands contains only ten star names, grouped in pairs in a$ and this is far too few to be really effective. In the example, ‘Antares’ = ‘Alpha Scorpii’, ‘Regulus’ = ‘Alpha Leonis’ — these are the alternative names for each star.’ Thus the program is ripe for expansion by the user perhaps with entirely different paired names.

The program
The program works in the following way. A DIMensional array is set up in line 30 to accept (in this case) 10 names with a maximum length of 13 characters to cope with the longest a$ – a$(2), a$(6) and a$(10) all have a total of 13 letters and spaces. A DIM b$(13), a single DIMensioned array, is also set up to receive the answers to be INPUT in Line 230.

The computer asks the user up to ten questions via the FOR/NEXT f loop in Line 160. The variable z in Line 170 selects a RANDOM number between 1 and 10 and PRINTs to the screen the a$ with this number. The computer also decides that the answer will be:

a$(z + t)

where variable t acts as a switch eg

if z = 1 then t = 1 if z = 2 then t = – 1

and so on for each odd or even number that is thrown up for z so that t has a value of 1 or – 1 as the case may be. If a$(l) to a$(10) in Lines 40 to 130 inclusive are checked, then it can be seen that the computer has identified each answer correctly by grouping the a$ in pairs.

Line 230 INPUTs and PRINTs the answer, and the ‘?’ is overprinted by using the expression PRINT CHR$ 8; b$. Lines 310 and 320 mark the answers and tot up the correct results with the variables score which is PRINTed at the end of the f loop.

The program uses the automatic scroll conditions by POKEing (POKE 23692, 255) and PRINTing below screen line number 21, so that the questions and answers flow up from the bottom of the screen next to the INPUT line 22. This is effected by program Line 350. Figure 9.5 is a typical COPY of the screen display.

Figure 9.5

Although the computer is looking for an answer which is precisely correct in upper and lower case lettering, there are insufficient permutations in a range of numbers from 1 to 10 without frequent repetition. Ideally the minimum should be about 30 questions, ie 15 paired questions/answers — preferably more to avoid repetition. Amending the program to receive extra questions involves minimal changes and can be done in two ways.

1) Additional listing in the a$
This is fairly straightforward and simply means squeezing more a$s into the listing, starting at a$(ll) — assuming the first 10 questions/answers in the listing are to be retained. For neatness, Lines 40 to 130 should be renumbered (perhaps as Lines 40 to 50 inclusive) and the extra new items for the a$ started from Line 51:

51 LETa$(11) = “…star name 6a…”
52 LETa$(12) = “…star name 6b…”
53 LETa$(13) = “…star name 7a…”
54 LETa$(14) = “…star name 7b…”
55 LETa$(15) = “…

and so on with all the extra data. Finally, amend the DIMensional array in Line 30 to account for the extra questions included:

30 DIM a$ (total number in a$, 13): DIM b$(13)

and amend the last value in the Line 170:

170 LET z = 1 + INT (RND*total number of questions in a$)

The program can now be RUN (RUN because all the program is contained in the LISTing).

2) INPUT subroutine
There is no particular need for the questions and answers to appear in the program and they can be INPUT via a subroutine. The procedure is as follows:

Delete Lines 20 to 130 inclusive

Amend Line 280 (final command) to GOTO 1 (in lieu of RUN)
Add the subroutine 400 DIM a$(50,13): DIM b$(13)

This allows for 50 questions/answers — 25 pairs — a maximum of 13 characters long, including spaces.)

410 FOR n = 1 TO 50
420 PRINT n; ” “; LET c$ = “”
430 INPUT c$ : PRINT c$
440 IFc$ = “stop” THEN STOP
450 LET a$(n) = c$
460 NEXT n: STOP

The subroutine is started with GOTO 400 and the paired questions/answers are INPUT sequentially. It is not necessary to use up all the DIMension a$ array if you run out of questions as long as the last INPUT was an even numbered item. Simply INPUT “stop” and Line 440 will STOP the program. The program should now be SAVEd with GOTO 9990 as a precaution and VERIFYed. Now amend Line 170 to read:

170 LET z = 1 +INT(RND*(n-l))

The variable n is the last value + 1 used in the INPUT loop in Line 440. The program should be SAVEd and VERIFYed as version no 3 by amending Line 9990 to read:

9990 SAVE “startest3” LINE 1

and then, as a direct command, GOTO 9990. The amendment will ensure that the program starts automatically when LOADed with LOAD “”or LOAD “startest3” (which is preferred) and so avoid the pressing of the RUN key which will erase all the DATA from the computer. All would not be lost of course — simple reLOAD but this time enter GOTO 1.

Now that the program is safely on tape, it is time to test the program started with GOTO 1.

Adding more questions
If less than the full quota of 50 questions/answers was initially INPUT, then more can be added by BREAKing the program and entering as a direct command:


which will pick up the INPUT routine where it left off and start the n loop again. Again the INPUT can be terminated before all 50 items have been entered with:

INPUT “stop”

and as a direct command to restart the quiz with GOTO 1. The current value of n will again update the maximum RANDOM number for the variable z. It is a wise precaution to SAVE each version where more DATA is INPUT before the quiz is tested. Better safe than sorry.

10 REM Star Tester
30 DIM a$(10,13): DIM b$(13)
40 LET a$(1)=”Antares”
50 LET a$(2)=”Alpha Scorpii”
60 LET a$(3)=”Regulus”
70 LET a$(4)=”Alpha Leonis”
80 LET a$(5)=”Betelgeuse”
90 LET a$(6)=”Alpha Orionis”
100 LET a$(7)=”Vega”
110 LET a$(8)=”Alpha Lyrae”
120 LET a$(9)=”Rigel”
130 LET a$(10)=”Beta Orionis”
140 LET score=0
160 FOR f=1 TO 10: LET t=1
170 LET z=1+INT (RND*10)
180 LET q=z/2
190 IF INT q=q THEN LET t=-1
200 GO SUB 340
210 PRINT f;”)”;a$(z);” is? “;
220 LET x$=a$(z+t)
230 INPUT b$: PRINT CHR$ 8;CHR$ 8;” “;b$
240 GO SUB 300: LET x=z
250 GO SUB 340: PRINT : NEXT f
270 GO SUB 340: PRINT “Your score: “;score;” correct answers”
280 PRINT FLASH 1;” Try again? – press any key “: PAUSE 0: RUN
300 GO SUB 340
310 PRINT PAPER 5; FLASH 1 AND b$x$;x$;
320 IF b$=x$ THEN LET score=score+1: PRINT PAPER 6; FLASH 1;” is correct”: GO TO 340
330 PRINT PAPER 5;” is the answer!”
350 POKE 23692,255: PRINT AT 20,0: PRINT : RETURN


Chapter 8 – Starcharts (Stellar Magnitude)

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.

Stellar Magnitude

Astronomers have a scale to measure the apparent brightness of the stars called magnitude. This was first classified by Hipparchus in 127 bc: he described ‘the brightest stars as magnitude 1’ and ‘the faintest stars as magnitude 6’ with four steps in between. This basic system has been retained ever since, but of course refined and explained mathematically, principally by Pogson in the last century. Pogson ascribed a value of 2.512 to 1 as a ratio between one whole magnitude and the next. This equates to a ratio of 100:1 for a star of first magnitude against a star of sixth magnitude just visible to the naked eye. Pogson also noted that the common logarithm of 2.512 is precisely 0.4, much simplifying computation.

This short program uses a simple FOR/NEXT loop to PRINT to the screen a magnitude range from -26 (the Sun) to +24 (faintest star detected with the 200-inch Hale telescope at Mt Palomar, California). The ratio to the standard star Vega at magnitude 0.0 is also displayed for each whole magnitude step. Our Sun proves to be 1:2.51E10 (25,000,000,000) times brighter than Vega: a magnitude +24 star proves to be about a similar ratio fainter than Vega.

Using a series of conditional PRINT statements the list is punctuated by some mainly familiar objects that match particular magnitudes. The standard star Vega is made to FLASH to identify itself readily.

The Spectrum does not use common logs but natural logs (LN function) to a base of 2.71828 … so Pogson’s neat common log relationship has to be fudged in this program, via Line 80, to give a ratio of 100:1 over five magnitudes.

10 REM Stellar Magnitude
15 PRINT “Mag Name”,”1:ratio”
20 FOR n=-26 TO 24 STEP 1
30 PRINT PAPER 6;(” ” AND ABS n0);n;” “;
37 PAPER 5
40 PRINT “Sun” AND n=-26;
41 PRINT “Full Moon” AND n=-13;
42 PRINT “Venus” AND n=-4;
43 PRINT “Sirius” AND n=-1;
50 PRINT FLASH 1;”Vega-standard” AND n=0;
51 PRINT “Uranus” AND n=5;
52 PRINT “Neptune” AND n=8;
53 PRINT “Barnard’s Star” AND n=10;
60 PRINT “Pluto” AND n=14;
61 PRINT “200”” eye limit” AND n=19;
62 PRINT “200””photolimit” AND n=24;
70 PAPER 7
80 PRINT TAB 18;EXP (LN 2.51193*-n): NEXT n

Chapter 8 – Starcharts (Startrax)

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.

Startrax (Stellar Proper Motion)

Astronomy, the study of the heavens, is the oldest science known to man: it dates back to 2000 BC, to the Chaldeans of Asia Minor. The star groupings or constellations familiar today were named by them. A remarkable feature of the constellations is that after 4000 years they appear virtually identical to us today as they did to those early astronomers — despite the fact that we know most stars are moving through space at tens of kilometres per second.

Why are the constellations not distorted beyond recognition by this random motion? Quite simply, the stars are so remote — distances measured in tens or hundreds of light years — the individual movements are undetectable to the unaided eye. Only one star, Arcturus at 36 light years distance, has moved appreciably since early Greek star maps were prepared. And even this amount is very little — about the diameter of the full moon, ie½°.

To see the constellations change shape, it is necessary to have a time scale of hundreds of thousands of years and this program simulates this effect on two selected star groups — the Plough and Orion. The DATA is taken from Hutchinson’s Splendour of the Heavens (1923). You have the option of allowing the individual stars to ‘trail’ their image across the screen or to PLOT as a moving pixel. The screen is presented in inverse video — BORDER 0: PAPER 0: INK 9.

In order that the PLOTting of the constellation selected is as smooth as possible, the individual star positions in the a$ are entered into DIMensional arrays x and y, the coordinate positions of each star. These arrays incorporate the ‘proper motion values’, as they are called, from the m$. How these values in the m$ are constructed will be described in detail later.

Economising memory
The method of handling the DATA is economical on the Spectrum memory (RAM). Although there is no real necessity in this case to save memory, the technique may be of interest and perhaps of use in your programming. As noted, the a$ contains the star positions and these are held as two 2-bit numbers:

Line 90
09 (x coordinate star 1)
17 (y coordinate star 1)
18 (x coordinate star 2)
22 (y coordinate star 2)

and so on to the end of the string array (star 16).

The m$ contains two 1-bit numbers per star to indicate the star’s xx,yy proper motion, so the LENgth of the respective m$ is precisely half that of the associated a$. The a$ and m$ are repeated to the end of the DATA: each pair is used for a separate constellation. In order that the correct DATA is used on RUNning the program a conditional GOTO must be incorporated immediately after each pair of string arrays, ie:

110 IF b$(l) = “P” THEN GOTO 150

then the program will jump out of the DATA, carrying the last values of a$ and m$ which were read. The last pair of string arrays does not need a conditional GOTO as it is assumed to be the selected pair by default. Between lines 110 and 120 there is room for three more constellations via your DATA without renumbering or using multiline statements.
Remember that the first letter of the b$ (used to INPUT the name of the constellations in line 30) must be included in the associated conditional GOTO. The example in Line 110 is ‘P’ for the Plough. By only requiring one letter (the first) to be correct, the program will ignore user misspellings (a necessary precaution as some of the constellation names can be very difficult).

Selecting DATA
The LENgth of the m$ is now used to DIMension to x and y arrays and the routine to Line 270 is used to enter the DATA into these arrays. In the case of Orion, with 20 stars and 20 positions for each star to be computed for subsequent PLOTting, this makes 400 x and 400 y positions. While the Spectrum does the necessary computation it displays a neat little ‘I am computing’ routine. Of course you could place every constellation (whether called upon for immediate display or not) into a DIMensional array but at 800 bytes per constellation it seems a little unnecessary for this program at least. In this program, the arrays are only reDIMensioned if the alternative constellation is called for display. Lines 50 and 60 recognise this condition and jump straight to the display if the same constellation is selected be it for a trailed or ‘point image’.

Proper motion values
The point of this program lies in the proper motion values in the m$, which permits stars to move in any direction and velocity across the screen. Figure 8.15 explains the principle.

Figure 8.15
Typical grid layout for estimating the relative motion of stars in a Proper Motion program. + in the centre of the grid marks the point of rest (ie no motion required). The xx and yy coordinate positions are measured from the bottom right corner. Note that the east (e) and west (w) positions appear reversed from the normal convention. It is usual in astronomy to represent the skies above our heads with east to the left of south, which is the case here.


Figure 8.16
Examples of typical values which could be used in the program. The further the selected coordinates are from the centre of the grid the faster a star will move in that direction. These values are incorporated into the m$ until all the stars in the constellation are included.




Figure 8.17
The familiar star pattern of Orion as seen today.


Figure 8.18
The apparently random motion of the stars in Orion over 200,000 years.


The grid is divided into nine horizontal (xx coordinate) and nine vertical (yy coordinate) boxes, a total of 81 boxes. To be different from the Spectrum PRINT and PLOT systems these coordinates start from the bottom right position. A star at ‘rest’ is placed at the centre of the grid and has an xx, yy coordinate value of 55. As a star is placed further from the centre of the grid, the velocity increases proportionally and in the direction indicated. For example a value of 46 indicates a small movement towards the NW (the top right corner). A value of 19 indicates the largest movement to the NW direction and so on for all points of the compass. Some typical sample values are shown in Figure 8.16.

Before the m$ VALue is entered into the x and y arrays, a value of – 5 is deducted from each number. Thus our m$ VALue of 55 becomes 00, ie no relative motion, and 46 becomes -1 +1. In this way only positive numbers need to be contained in the m$ although the required VALues are sometimes negative. The conversion is done in Lines 180 and 190. The FOR /NEXT f loop from Line 220 allocates the values to the x and y arrays which are incremented by the m$ values in Lines 230 and 250. In the final display the FOR/NEXT loop contains 20 STEPs and the middle STEP 10 represents the form of the selected constellation as we know it today. Thus a brief but powerful program results.

Screen display
The method of preparing starmaps on the Spectrum is described more fully in the Starmaps program. Let it suffice here to say that this example uses a screen resolution of 64*44 pixel positions in the DATA of the a$ and that this is expanded to the full 256*176 of the Spectrum by multiplying each PLOT position in Line 360 by 4. One point should be observed if you extend the program to include your own selected constellations. Avoid the edge of the screen with your basic starmaps. The proper motion in a star’s movement will cause the program to crash if it attempts to PLOT beyond the maximum coordinates (255 for x; 175 for y). Figures 8.17 and 8.18 are typical screen COPYs.

10 REM Startrax
20 LET c$=””
30 INPUT FLASH 1;”Plough or Orion “;b$
40 INPUT “Trailed or point images (t/p)? “; LINE t$
50 IF c$=b$(1) THEN GO TO 290
60 LET c$=b$(1)
80 INK 9: FOR n=1 TO 9: PRINT PAPER n; FLASH 1;AT 5+n,11;”COMPUTING”: NEXT n: GO SUB 500
90 LET a$=”09171822252133203614472648195321″
100 LET m$=”3594938484268484″
110 IF b$(1)=”p” OR b$(1)=”P” THEN GO TO 150
120 LET a$=”2533333736313020322134223214280940113619″
130 LET m$=”94499797497995954949″
150 DIM x(LEN m$,20)
160 DIM y(LEN m$,20)
170 FOR n=1 TO LEN m$ STEP 2
175 LET h=n*2
180 LET d=VAL m$(n)-5
190 LET e=VAL m$(n+1)-5
200 LET a=VAL a$(h-1 TO h)+d
210 LET b=VAL a$(h+1 TO h+2)+e
220 FOR f=1 TO 20
230 LET a=a-d/10
240 LET x(n,f)=a
250 LET b=b-e/10
260 LET y(n,f)=b
270 NEXT f: NEXT n
290 CLS : PRINT INK 6; b$; “10chr$ 130” “,”in the distant past”,”year =”
300 FOR n=1 TO 20
310 LET y=-1e5+1e4*n
320 PRINT AT 2,6;y;” ”
330 IF t$=”t” THEN FOR f=1 TO 0 STEP -1
340 IF t$”t” THEN FOR f=0 TO 1
350 FOR p=1 TO LEN m$ STEP 2
360 PLOT BRIGHT 1; OVER f;x(p,n)*4,y(p,n)*4
370 NEXT p
380 IF y=0 AND f=0 THEN GO SUB 430
390 IF y=1e5 AND f=0 THEN GO SUB 420
400 PAUSE 1+10*(1-f)
410 NEXT f
420 NEXT n: GO SUB 500
425 GO TO 30
440 PRINT INK 5;AT 1,0;”Today’s “;b$;” “: GO SUB 500
450 PRINT INK 4;AT 1,0;”and in the future “: RETURN
500 FOR v=0 TO 5: FOR k=7 TO 0 STEP -1: BORDER k: BEEP .01,40-k: NEXT k: NEXT v: RETURN

Chapter 8 – Starcharts (Flashing Stars)

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.

Flashing Stars

There are two basic ways to make a star (a single pixel) flash ‘on’ and ‘off’ using the OVER command, and this can be useful in highlighting a particular point in your programs involving starmaps. You have the option of the star remaining visible or disappearing at the end of the flashing sequence.

Routine using two FOR/NEXT loops to flash a star The following one-line routine demonstrates the principles using two FOR/NEXT loops. The T loop controls the number of flashes and the ‘n’ loop acts to switch the OVER command on or off (1 or 0). It is necessary to include a brief PAUSE (PAUSE 10) to make the flashing obvious otherwise one is left with no more than a rapid flicker. It will be noted that the n loop finishes with a value of 0: in this way, the star remains visibly PLOTted at the end of the routine. If the values in the FOR/NEXT n loop are reversed thus:

…: FOR n = 0 TO 1 : …

(omitting the STEP routine as it is now superfluous), the star will disappear at the end of the routine with PLOT OVER 1 (ie unPLOT position of pixel).

1000 PRINT “flash star”: FOR f=0 TO 10: FOR n=1 TO 0 STEP -1: PLOT OVER m;200,100: PAUSE 10: NEXT n: NEXT f

Routine using a single FOR/NEXT loop to flash a star
This routine is probably easier to use and demonstrates the rather odd way in which the OVER command works. The OVER command is set to a value of 1 throughout — it unPLOTs (makes invisible) the pixel position.

However to unPLOT an unPLOTted pixel position via the next value in the FOR/NEXT loop, PLOTs the pixel back into visibility! Thus throughout the FOR/NEXT loop the OVER command becomes:

and the star will flash in the required manner

If the FOR/NEXT loop has an effective number of steps that are uneven (2 TO 10 = 9 STEPs) then the OVER command will finish with a value of 0 and the star will be PLOTted and visible at the end of the routine — see Line 1000. If the FOR/NEXT loop has an even number of steps (1 TO 10 = 10 STEPs in Line 1001) the star will disappear with a final PLOT OVER 1 condition.

1000 PRINT “flash star-on”: FOR f=2 TO 10: PLOT OVER 1;200,100: PAUSE 10: NEXT f
1001 PRINT “flash star-off”: FOR f=1 TO 10: PLOT OVER 1;200,100: PAUSE 10: NEXT f”

Chapter 8 – Starcharts (Star Graphics)

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.

Star Graphics

This short demonstration program shows how more complex shapes can be constructed for incorporating into starmaps. These images would represent the brightest stars to be displayed and as such should have geometric forms.

The program
The program is divided into three parts as indicated by the REM statements. The first part to Line 7 copes with the selection of images numbered 1 to 4 via the INKEYS command in Line 3. Line 8 contains two GOSUB commands — the first is conditional on the selection:

GOSUB 100 or 200 or 300 or 400

in the form GOSUB a x 100 where a equals the VALUE of INKEY$ from Line 4. At the appropriate GOSUB line, the selected star form is PLOTted and DRAWn according to its shape. The program then RETURNS to Line 8 for the second GOSUB (GOSUB 1000).

The third and final section of the program from Line 1000 uses the POINT command to scan the star image just PLOTted and enlarge it for easy viewing. Two FOR/NEXT loops are used (n and f) to cover the tiny area of the screen adjacent to the x and y coordinate positions of the small star image. Lines 1010 and 1020 take the form:

1010 IF POINT (x + n, y + f) = 1 THEN PRINT … “CHR$143”
1020 IF POINT (x + n, y + f) = 0 THEN PRINT … “CHR$58”

If POINT equals a value of 1 then PRINT a solid INK square character (ie a pixel is PLOTted at this location). Conversely, if POINT equals a value of 0 then PRINT a colon (ie a pixel is not PLOTted at this location).

Line 1020 is not really necessary to define the star shape but it does help to locate its relative position by marking the unPLOTted points. The program then RETURNS for the next selection.

Further star shapes can be included in the program, starting at Line 600 in steps of one hundred (700, 800, 900, and so on). This is to satisfy the conditional GOSUB in Line 8. The value 4 currently set in Line 3 and Line 5 should be amended for each additional shape included in the program. The final statement in each new PLOT and DRAW section must conclude with RETURN.

It is useful to sketch the new star shapes on squared paper before committing them to the program but it is not essential. You can simply start with a PLOT x,y condition and then add DRAW commands (preferably with quite small values — certainly no greater than a value of 6) and RUN the program to test the new design. If it is unsatisfactory then change it. The aim should be to contain all the new design within the portion of the screen scanned by the POINT command and displayed in enlarged form.

Incorporating results in a starmap program
A subroutine virtually identical to this program could be incorporated in a starmap program to represent some of the brighter stars. Only Lines 100 to 499 (plus any extra lines for your own designs) are required in such a subroutine together with some control lines to make the subroutine work. These would be in the main program area dealing with PLOTting the stars and could take the form:

star PLOTting routine where x and y are star coordinates.
IF n = 1 THEN GOSUB 400 : REM mag 0 star = brightest
IF n = 2 THEN GOSUB 100 : REM mag 1 star
IF n = 3 THEN GOSUB 300 : REM mag 2 star
IF n = 4 THEN GOSUB 200 : REM mag 3 star
If n > 4 THEN PLOT x,y: REM mag 4 are PLOTted as a single pixel and represent the faintest stars.

These conditional sample lines shown above are only one example of what could be used in the program. The permutations are endless. Suppose for example that the first three stars are to be magnitude 0 (the brightest) in each constellation of the starmap and the next two stars of magnitude 1, then the routine would read:

IF n<4 THEN GOSUB 400: NEXT n: REM mag 0 stars 1 to 3
IF n<6 THEN GOSUB 100: NEXT n: REM mag 1 stars 4 and 5
If n=6 THEN GOSUB 300: REM mag 2 star 6

and so on through the sequence as required. Note that the first two conditional lines must include the statement NEXT n so that the program does not proceed beyond that line until the condition is satisfied.

Figure 8.14
Typical shapes to represent brighter stars on computer starmaps. Shown enlarged here for clarity. The POINT command, via two FOR/NEXT loops, is used to scan the actual (tiny) images to the left of each sample which are used in the final starmaps.





2 PRINT “Star Graphics “;
3 PRINT “1 to 4=”;INKEY$
6 LET x=99: LET y=80
7 PRINT AT 0,21;a
8 GO SUB a*100: GO SUB 1000
9 PRINT AT 0,0;: GO TO 1
100 PLOT x,y: DRAW 2,2
110 DRAW 2,-2: DRAW -2,-2
120 DRAW -2,2
200 PLOT x,y: DRAW 0,2
210 PLOT x+1,y+1: DRAW -2,0
300 PLOT x,y: DRAW 1,1
310 DRAW 1,-1: DRAW -1,-1
400 PLOT x,y: DRAW 4,0
410 PLOT x+2,y-2: DRAW 0,4
420 PLOT x,y-2: DRAW 4,4
430 PLOT x,y+2: DRAW 4,-4
440 PLOT OVER 1;x+2,y
1000 FOR n=0 TO 5: FOR f=0 TO 5
1010 IF POINT (x+n-1,y+f-2)=1 THEN PRINT AT 10+f,16+n;CHR$ 143
1011 IF POINT (x+n-1,y+f-2)=0 THEN PRINT AT 10+f,16+n;CHR$ 58

Chapter 8 – Starcharts (Stellar Magnitudes)

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.

Stellar Magnitudes

Stars that we see in the sky vary enormously in brightness — by a factor of over 100: from brightest to faintest. The programs in this book generally omit such differences for the sake of simplicity, and use a single pixel to PLOT each star on, for example, the Starmaps program. There are two basic ways to distinguish these stellar differences on the Spectrum screen and the three routines which follow can easily be incorporated into programs.

The first method relies on PLOTting additional pixels to form a larger image: the second uses progressively darker shades of INK to PLOT the pixel. Obviously the latter is only suitable for a monochrome presentation and the star positions must be sufficiently well separated so as not to occur in the same character square (as this will only support a single INK colour.). Nevertheless the second method has the merit of realism (in monochrome) in that the star images remain small. The third method combines the first two — again this is only suitable for monochrome but has the maximum potential of brightness range.

1: Extra pixel plotting
Key in and RUN the Star Magnitudes 1 routine in Figure 8.10, and the screen is filled with star-like images that get progressively smaller down the screen as a regular grid. Each star is PLOTted initially only as a single pixel but is enlarged by the conditional DRAW routines that immediately follow. This takes the form of a FOR/NEXT n loop and stars that are PLOTted first (with the lower n values in their PLOT position) are conditionally dealt with as:

IF n<3 THEN DRAW 0,1
IF n<6 THEN DRAW 1,0
IF n<9 THEN DRAW 0,-1

Figure 8.10
3000 PRINT “Star Magnitudes 1 @”
3030 BORDER 0: PAPER 1: INK 9
3040 LET z=0
3050 FOR n=1 TO 12
3060 PLOT z,n*10-150
3070 IF n<3 THEN DRAW 0,1
3080 IF n<6 THEN DRAW 1,0
3090 IF n<9 THEN DRAW 0,-1
3100 NEXT n
3200 LET z=z+20: GO TO 3050

Figure 8.11 shows precisely how each image is PLOTted and then DRAWn. Only one extra pixel is added by each conditional line — the value 1 in each DRAW statement.

Figure 8.11
Using conditional DRAW statements to enlarge a single pixel into a brighter star. Shown here in four steps. Because the individual pixels are not easily seen at normal viewing distances from the TV, the image just appears enlarged.


2: Colour tone (in monochrome) plus extra pixel plotting
Amend Star Magnitudes 1 to Star Magnitudes 2 (Figure 8.12) and RUN it. If a colour set is used for the display then the colour control should be adjusted to a monochrome picture. This then shows how the INK tone considerably extends the apparent range of star brightness, particularly for fainter stars. The limitations of such a scheme are mentioned earlier in this section.

Figure 8.12
3000 PRINT “Star Magnitudes 2 @”
3030 BORDER 0: PAPER 1: INK 9
3040 LET z=0
3050 FOR n=1 TO 12
3051 INK 9-n/2
3060 PLOT z,n*10-150
3070 IF n<3 THEN DRAW 0,1
3080 IF n<6 THEN DRAW 1,0
3090 IF n<9 THEN DRAW 0,-1
3100 NEXT n
3200 LET z=z+20: GO TO 3050

3: Colour tone (in monochrome)
The third version (Figure 8.13) is prepared by deleting all the conditional DRAW lines in the second routine before it is RUN. A practical version of this routine, for incorporating into a longer program (with the limitations already mentioned), would take the form:

PAPER 0: INK 9: REM dark tone most stars = INK 2
FOR n = 1 TO 12
IF n5 THEN PLOT; INK 2; x(n), y(n): REM faint stars

The relative brightness of the stars are controlled by the expression

INK 8-n

for the first five stars (n5) would have an INK tone value of 2 (INK pixel colour red). It is possible to extend the range to include an extremely faint star by using an INK tone value 1 (INK pixel colour blue) but on a black sky (PAPER 0) a single pixel may be undetectable.

Figure 8.13

3000 PRINT “Star Magnitudes 3 @”
3030 BORDER 0: PAPER 1: INK 9
3040 LET z=0
3045 BRIGHT 1
3050 FOR n=1 TO 12
3051 INK 9-n/1.5
3060 PLOT z,n*10-150
3100 NEXT n
3200 LET z=z+20: GO TO 3050

Starcharts with magnitude control
To incorporate any of the above routines into a longer program, you will need to take care in the order in which you PLOT each star. The brightest stars should be listed first and so on in decreasing order of brightness. If a particular constellation has no bright stars it is necessary to repeatedly PLOT the same star before PLOTting the next star, until the correct INK tone is used. This means that more apparent star positions will be listed than finally appear on the screen.

To satisfy the above condition with the first method (extra pixel plotting) then the PLOTting may have to include more conditional statements so that a particular constellation skips some of the extra pixels that otherwise would be DRAWn. This could take the form:

FOR n = 1 TO 30: REM 30 constellations
FOR f = 1 TO (no of star positions) STEP 2
PLOT x(n,f), y(n,f+1): REM x,y = star coordinates
IF n=5 AND f=1 THEN GOTO XXXX : REM skip DRAW routine for constellation no 5, star 1
IF f<3 THEN DRAW 0,1
IF f…
NEXT f: NEXT n (NB line XXXX)

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