top of page

LOADING...

SCREECH

Vintage & Modern Tech Blog

Stephen Nichol

< FIVE MINUTE BASIC #4 - Firework Display

This program creates a random, multi-coloured firework display on your Sinclair ZX Spectrum computer.

By some strange coincidence there was a fireworks display put on near where I live only a couple of days ago as the airshow is here.

Unfortunately for the people attending the first night of the show, the fireworks were the only objects in the air as the planes couldn't fly due to low level cloud.

The weather cleared up today, however, but I still sat at home and worked out this little Firework Display program for you instead of going to see the aircraft.

As usual there is an explanation/refresher at the bottom of the listing for anyone who may need a few pointers as to what on earth they just typed in. I've also added some REMarks into the program, for easier reading once the program is actually in the computer or emulator. Right, I guess I'd better stop waffling...

This is a slightly longer listing, so let's break it up into parts;

First type in;

10 REM Firework Display 20 REM Stephen Nichol 2014 30 LET p=0: LET i=7 40 BORDER 0: PAPER p: CLS 50 LET y=20 60 LET x=RND*27 70 INK i 80 IF x<5 THEN LET x=5 90 PRINT AT y,x;"^": REM Ignore this symbol - I used the one on Symbol Shift + H key. 100 PAUSE 25 110 REM *** Fire a 'rocket' at random y, definite x position *** 120 FOR y=19 TO 7 STEP -1 130 PRINT AT y,x;"^": REM Again, Symbol Shift + H key. 140 PRINT AT y+1,x;" ": REM Print a blank space one below the moving rocket. 150 IF y=7 THEN PRINT AT y,x;" ": GO TO 180 160 NEXT y

If you want have a rest. Now, directly after line 160, type-in;

170 REM *** Random patterns in sky *** 180 FOR Y=7 TO 3 STEP -1 190 LET q=y-RND*3: LET w=x-RND*4 200 PRINT AT q,w;"*" 210 LET e=y-RND*3: LET r=x+RND*4 220 PRINT AT e,r;"*" 230 LET t=y+RND*3: LET u=x-RND*4 240 PRINT AT t,u;"*" 250 LET i=y+RND*3: LET o=x+RND*4 260 PRINT AT i,o;"*" 270 NEXT y 280 PAUSE 25 290 REM *** Make it look like the fireworks are

disappearing slowly *** 300 FOR Y=7 TO 3 STEP -1 310 LET m=10 320 PRINT INK p;AT e,r;" " 330 PRINT INK p;AT i,o;" " 340 PRINT INK p;AT q,w;" " 350 PRINT INK p;AT t,u;" " 360 PAUSE 5 370 CLS 380 NEXT y 390 GO TO 50

Explanation/Refresher(if required):

Lines 10 and 20 are REMarks, comments that do not affect the running of the program.

Lines 30 and 40 do something very useful. Rather than entering just Paper 0, or paper 2 to get a coloured display, instead we assign the paper colour to the letter 'p'. Now, at any point that we want the paper to be that colour, we put Paper p, and if we decide that we don't want that colour then we just change line 10 and let p= a different number colour. I'm also using i for ink for the same reason.

Line 50 tells the computer to always generate our firework rocket at the same height (y).

Line 60 tells the computer to choose a random left to right (x) position

of up to 27 character cells from the left of the display area.

Line 80 is in this program because of something I know that is going to happen - the firework is going to spread out when it is higher up the screen. An error message would appear if the spraying particles from the firework were to go beyond the edge of the screen. I could make them appear on the other side of the screen, but I don't want to, so I tell the computer that IF the X (left to right) value is less than 5, make it just 5 and then continue.

Lines 120 to 160 are a FOR...NEXT loop that deal with transporting the firework up the screen to the top. Once the firework has reached a height of 7 on the Y axis (the seventh low-res text line from the TOP of the screen. If you were using high-res commands like PLOT, DRAW, or CIRCLE, then it would be worked out differently).

Lines 180 to 270 are another FOR...NEXT loop that generates random patterns once the firework rocket has reached the top area of the screen. Although these random patterns are not going to win any awards, they are still fairly interesting to watch.

Lines 300 to 350 remove some of the asterisks from the screen, creating the illusion of the firework display disappearing piece by piece.

Line 360 pauses very briefly before the screen is cleared in Line 370.

Line 380 closes the FOR...NEXT loop until it reaches, in reverse from 7 the number 3.

Line 390 goes back almost to the beginning to repeat this process. We don't want it to go all the way back to the beginning, or we would end up with a lot of static fireworks at the bottom of the screen.

23 views

Related Posts

See All
bottom of page