SNOW
Author: regregex
Category: Christmas Challenge
System: Sinclair ZX Spectrum 16K/48K/128K/+2/+2A
Language: Spectrum BASIC
Len source code: 292 bytes
Len exe file: 184 bytes
Len code only: 159 bytes
Instructions:
Install and open Speccy ( https://fms.komkon.org/Speccy/ ).
Click File -> Open, select autoload.tap.
On hardware, enter:
LOAD "" J <SymbolShift+P> <SymbolShift+P> <Enter>
and play the tape. To run, enter:
RUN R <Enter>
Description: The program displays a specific snowflake pattern on 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.
1 A leading line number puts the line in memory:
CLS : Clear the screen.
LET P=CODE "b": Set P := 98, square of the radius of the shape
LET N=INT SQR P: Set N := 9, length of each axis from the origin
LET E=SGN N: Set E := 1
FOR Y=-N-E TO N: Loop over rows -10 to 9, first row is blank:
PRINT : Move the cursor down, leaving row 1 also blank.
FOR X=P-CODE "r" TO N: Loop over cols -16 to 9, first 7 blank:
LET H=Y*Y+X*X: H := square of the Euclidean distance from (0,0)
LET R=N+E+E R := 11, last character of radius string
2 IF R AND H<P THEN Skip if string exhausted ( ) or point=(7,7) (*)
IF Nested IFs act as a fast, lower-precedence AND
CODE "EBW7b6i-m'o"(R) Select R'th character and get its value
-CODE "%" Subtract 37 obtaining number in (2..74)
<>H If it doesn't match our radius
AND X*Y THEN and if the point is not on an axis (X*Y<>0)
LET R=R-E: then step to previous character
GO TO E+E and redo this line; else R remains >0
3 PRINT " *" Print either space or asterisk
(E FALSE=0, TRUE=1 but string offsets start at 1
+(R>=E AND H<=P));: "*" if match found and within bounds
NEXT X: Loop until last column
NEXT Y: Loop until last row
PAUSE E-E Wait for keypress (PAUSE 0) and exit
The radius table contains 11 entries but defines 12 stars per octant.
This is because:
7^2 + 1^2 == 5^2 + 5^2.
As point (5,0) has an inconvenient alias, the lookup table is not used
for points on the axes.
Created with SpecIDE ( https://github.com/MartianGirl/SpecIde/releases )
which saves TAP files, but is a little trickier to use.