SNOW
Author: regregex
Category: Christmas Challenge
System: BBC Micro A/B/Master, Acorn Electron
Language: BBC BASIC
Len source code: 116 bytes
Len exe file: 94 bytes
Len code only: 94 bytes
Instructions:
Install and open BeebEm ( http://www.mkw.me.uk/beebem/ ).
Click File -> Run Disc, select bbcsnow.ssd.
On hardware, insert the disc then tap BREAK while holding SHIFT.
Description: The program runs under BBC BASIC version 1 and up, and
displays a specific snowflake pattern on the screen.
It selects display MODE 4, which automatically clears the screen.
For each character cell in a large rectangle in the top left corner it
then calculates the Euclidean distance from the centre, and prints an
asterisk if the radius is within a prescribed limit AND in a lookup
table of radii, or if the cell lies on an axis. The program waits for a
keypress before exiting.
Comments: An annotated dissection of the code follows. Abbreviations
have been expanded for clarity.
0 A leading line number puts the line in memory:
MODE4: Display MODE 4 is preferred for square pixels.
FORY=-14TO9: Loop for 24 rows of which five are blank:
PRINT: Move the cursor down, leaving row 0 also blank.
FORX=-20TO9: Loop for 30 columns per row, first 11 blank:
H=Y*Y+X*X: H := square of the Euclidean distance from (0,0)
VDU Send one character to the VDU routine:
32EOR10AND " " if Boolean expression is FALSE, "*" if TRUE
H<99AND( All asterisks are within 7*SQR(2) of the origin
X*Y=0OR All points on axes starred (can't lookup (0,0)!)
0<INSTR( Search a string for a substring, return index
"o'm-i6b7WBE", 11 radii define 76 stars due to aliasing
CHR$( Turn square of radius into a printable character
37+H MOD90 Choosing modulo 90 wins us one alias
))): Index converted to TRUE if a substring is found
NEXT,: Loop until last column, then until last row
IFGET Collect a character from console and discard it
The radius table contains 11 entries but defines 13 stars per octant.
This is because:
2^2 + 2^2 == 7^2 + 7^2 (mod 90), and
7^2 + 1^2 == 5^2 + 5^2 (mod 90).
As (0,0) and (5,0) each have an inconvenient alias, the lookup table is
not used for points on the axes.