Skip to content

Instantly share code, notes, and snippets.

@root42
Last active November 19, 2022 17:15
Show Gist options
  • Save root42/68c7a1d52d59bc1078ae236b84710c27 to your computer and use it in GitHub Desktop.
Save root42/68c7a1d52d59bc1078ae236b84710c27 to your computer and use it in GitHub Desktop.
Let's Code MS DOS 0x1E: Power BASIC Snowflake
DIM angle AS SHARED DOUBLE
DIM COL AS SHARED INTEGER
DIM SCALE AS SHARED DOUBLE
'-------------------------------------------------------------------
' Make a turn in the curve, given in degrees
'-------------------------------------------------------------------
SUB turn (degrees AS DOUBLE)
angle = angle + degrees*3.14159265/180
END SUB
SUB minus
turn 60
END SUB
SUB plus
turn -60
END SUB
'-------------------------------------------------------------------
' Draws one step forward in the curve
'-------------------------------------------------------------------
SUB forward (length AS DOUBLE, col as INTEGER)
LINE - STEP (COS(angle)*length, SIN(angle)*length), col
END SUB
'-------------------------------------------------------------------
' Draws a Koch curve
' - DEPTH : number of subdivisions
'-------------------------------------------------------------------
SUB KOCH(depth AS INTEGER)
' axiom of the Koch curve
F depth
minus
minus
F depth
minus
minus
F depth
END SUB
'-------------------------------------------------------------------
' Draws one iteration of the Koch curve
'-------------------------------------------------------------------
SUB F (depth AS INTEGER)
IF depth=0 THEN
forward SCALE, col
ELSE
F depth-1
plus
F depth-1
minus
minus
F depth-1
plus
F depth-1
END IF
END SUB
'-------------------------------------------------------------------
' Main program
'-------------------------------------------------------------------
SCREEN 12
RANDOMIZE TIMER
angle = 0
count = 0
WHILE INSTAT = 0
IF count > 100 THEN
CLS
COUNT = 0
ELSE
COUNT = COUNT + 1
END IF
DEPTH = 4 ' maximum recursion depth
STRIDE = 5 ' length per line; needs to be bigger than depth
SCALE = (STRIDE - DEPTH) * STRIDE * (0.2 + RND)
X = -160 / SCALE + RND * 640
Y = -120 / SCALE + RND * 480
COL = 1 + INT(RND * 16)
PSET (X,Y), COL
KOCH(DEPTH)
SLEEP 1
WEND
SCREEN 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment