The Self-Writing Snowflake (VCCC 2025)
- Type
- Demo
- Category
- Self-modifying BASIC: a program that types in its own program
- Author
- reifsnyderb
- Published in
- AtariAge forums, "Logiker's Christmas Challenge VCCC 2025" thread (December 2025)
- Year
- 2025
- Language
- Atari BASIC
- Requirements
- Any 8-bit Atari with Atari BASIC and about 32K free; patience (or an emulator's warp speed)
About the program
Logiker's Vintage Computing Christmas Challenge 2025 asked entrants to draw a given star-pattern snowflake with as little code as possible. Most Atari entries were golfed down to a few dozen characters. reifsnyderb went the other way, "since I wasn't going to type all that stuff in". His program doesn't draw the snowflake. It writes a program that draws it. For every two-character cell of the screen and every star of the snowflake, it adds a pair of new BASIC lines (POSITION col,row and PRINT " " or PRINT "*") to itself, starting at line 10000, and then jumps to them. By his own account the generated program grows to around 20K, and in real Atari BASIC it takes a very long time to run. He suggests it might "win an award for the longest time to simply clear the screen".
Joke or not, it's a perfect demonstration of a classic Atari technique: a program that types into the screen editor by itself.
What you need
Atari BASIC and plenty of free memory. The author started with 32K free after DOS, and the 960 screen-clearing lines are the reason the blanks are printed two at a time. In an emulator, turn on warp speed.
Typing it in
{CLEAR}in lines 110 and 300 is the clear-screen character: press ESC, then SHIFT-CLEAR, inside the quotes. In the forum post it appeared as}(the same code, 125, in ASCII), as the author pointed out.- Line 160 prints two spaces between the quotes. Don't let them merge into one.
400 GOTO 10000jumps to a line that doesn't exist yet. The program creates it.
How it works: the forced-read trick
Each new line is made in three steps.
- Write it on the screen. Lines 110–170 (and 300–370 for the stars) clear the screen and print, a few rows down, a line number and a statement, for example
10000 POSITION 0,0, then10001 PRINT " ". - Print
CONTunderneath and move the cursor back up to row 4 (lines 800–810). - Let the editor "press RETURN" itself.
POKE 842,13puts the screen editor into auto-return (forced-read) mode, andSTOPdrops BASIC into immediate mode. The editor now reads every line on the screen from the cursor down as if RETURN had been pressed on each one. The numbered lines are added to the program, and when it reachesCONT, the program carries on from where it stopped. Line 830 sets location 842 back to 12 (normal mode) before returning.
The outer loops repeat this for 20×24 screen cells, then lines 300–390 READ the 113 star positions from the DATA in lines 1000–1200 (ended by 0,0), and finally GOTO 10000 runs the freshly written program. The same trick was used in the 1980s for things like merging DATA into a program or deleting a range of lines without a utility.
Variations to try
- LIST 10000,10020 after a run to see the code the program wrote for itself.
- Change the
"*"in line 360 to another character, or edit the DATA pairs to draw your own pattern.
Listing
10 LNUM=10000
100 FOR ROW=0 TO 23
105 FOR COL=0 TO 39 STEP +2
110 ? "{CLEAR}":POSITION 2,7:? ""
120 ? LNUM;:? " ";:LNUM=LNUM+1
130 ? "POSITION ";:? COL;
140 ? ",";:? ROW
150 ? LNUM;:? " ";:LNUM=LNUM+1
160 ? "PRINT ";:? CHR$(34);:? " ";
170 ? CHR$(34)
180 GOSUB 800
190 NEXT COL:NEXT ROW
300 ? "{CLEAR}":POSITION 2,7:? ""
310 READ COL,ROW
315 IF COL=0 THEN 400
320 ? LNUM;:? " ";:LNUM=LNUM+1
330 ? "POSITION ";:? COL;
340 ? ",";:? ROW
350 ? LNUM;:? " ";:LNUM=LNUM+1
360 ? "PRINT ";:? CHR$(34);:? "*";
370 ? CHR$(34)
380 GOSUB 800
390 GOTO 300
400 GOTO 10000
800 PRINT "CONT"
810 POSITION 2,4
820 POKE 842,13:STOP
830 POKE 842,12
840 RETURN
1000 DATA 20,2
1010 DATA 18,3,20,3,22,3
1020 DATA 13,4,15,4,19,4,20,4,21,4
1021 DATA 25,4,27,4
1030 DATA 14,5,15,5,20,5,25,5,26,5
1040 DATA 13,6,14,6,15,6,18,6,20,6
1041 DATA 22,6,25,6,26,6,27,6
1050 DATA 16,7,19,7,20,7,21,7,24,7
1060 DATA 17,8,20,8,23,8
1070 DATA 12,9,15,9,18,9,20,9
1071 DATA 22,9,25,9,28,9
1080 DATA 13,10,16,10,19,10,20,10
1081 DATA 21,10,24,10,27,10
1090 DATA 11,11,12,11,13,11,14,11
1091 DATA 15,11,16,11,17,11,18,11
1092 DATA 19,11,20,11
1093 DATA 21,11,22,11,23,11,24,11
1094 DATA 25,11,26,11,27,11,28,11
1095 DATA 29,11
1100 DATA 13,12,16,12,19,12,20,12
1101 DATA 21,12,24,12,27,12
1110 DATA 12,13,15,13,18,13,20,13
1111 DATA 22,13,25,13,28,13
1120 DATA 17,14,20,14,23,14
1130 DATA 16,15,19,15,20,15
1131 DATA 21,15,24,15
1140 DATA 13,16,14,16,15,16
1141 DATA 18,16,20,16,22,16
1142 DATA 25,16,26,16,27,16
1150 DATA 14,17,15,17,20,17
1151 DATA 25,17,26,17
1160 DATA 13,18,15,18,19,18
1161 DATA 20,18,21,18
1162 DATA 25,18,27,18
1170 DATA 18,19,20,19,22,19
1180 DATA 20,20
1200 DATA 0,0
Credits
- Program listing: The Self-Writing Snowflake (VCCC 2025) — program listing (AtariAge forums, "Logiker's Christmas Challenge VCCC 2025" thread (December 2025)) — reifsnyderb
- AtariAge forum — Logiker's Christmas Challenge VCCC 2025 (thread 386295) — reifsnyderb, 2025
- Vintage Computing Christmas Challenge 2025 (Logiker) — logiker.com, 2025
