A Star with PROCs
Author: atsampson
Category: Christmas Challenge
System: Acorn BBC Micro
Language: BBC BASIC
Len source code: 183
Len exe file: 159
Instructions:
bbc9.ssd is a disk image that should work in any BBC emulator or a real BBC.
For example, you could start B-Em with:
b-em bbc9.ssd
Or start MAME with:
mame bbcb -flop1 bbc9.ssd
Then type this to load and run the program:
CH."BBC9"
Description:
See the ASCII file bbc3.bas for an earlier, clearer version of the code;
bbc9.bas is the final version with some optimisation for size.
I'm sure this won't be the shortest BBC BASIC version, but I quite liked the
two techniques it uses:
- The shape has 8-way symmetry, so each star needs to be drawn in 8 reflected
locations. This can be done quite neatly in BBC BASIC by overlapping PROC
definitions, so to reflect on one axis, you call the next PROC with the
reflected arguments (e.g. -x, y) and then fall through into its definition
for the unreflected version (x, y). Stack up three layers of this and
you've got all eight reflections.
- Each 1/8th of the star can be drawn as two straight lines of 8 stars, plus
8 additional stars - so one loop can draw all three of these at once.
The final version turns the list of constants into a string, and unrolls some
of the PROCs where the unrolled version is shorter (boo).
Comments:
Mode 7 has the best-looking stars.