LOOKUP HRFORTH  ( HGR page 1 reserved )
NOT ?ABORT" Must run with HRFORTH."

SRC" PLASMA.4TH"
SRC" CONIO.4TH"
SRC" HGRLIB.4TH"
SRC" TURTLE.4TH"

: SHOW
  40 _TEXT DROP
  0 19 40 4 VIEWPORT
  0 HGRMODE HGRDRAWBUF DROP
  $C053 C@ DROP
  280 160 [ LOOKUP LINESPANS ] LITERAL INITTURTLE
  3 HGRCOLOR
;

: SQUARE
    DUP MOVE 90 TURN
    DUP MOVE 90 TURN
    DUP MOVE 90 TURN
        MOVE 90 TURN
;

: SPIN
    361 0 DO
        100 SQUARE
        I TURNTO
    10 +LOOP
;

: ZOOM
    361 0 DO
        I MOVE
        -122 TURN
    5 +LOOP
;

: SPIRAL
    361 0 DO
        I 4 / MOVE
        20 TURN
    LOOP
;

: CLEAR 0 0 279 159 HGRRECT ;

: CLEARTO HGRCOLOR 0 0 279 159 HGRRECT ;

: INVERT 0 0 279 159 HGRXORRECT ;

: RESET PENUP 140 80 MOVETO 0 TURNTO PENDOWN ;

1 VARIABLE MAXDEPTH

1 VARIABLE DEPTH

: POW3
    1 SWAP 1- ?DUP 0= IF EXIT THEN
    0 DO
        3 *
    LOOP
;

: TRIEDGE
    DEPTH @ MAXDEPTH @ = IF
        8960 DEPTH @ POW3 / 1+ 1 RSHIFT MOVEP4
    ELSE
        1 DEPTH +!
        RECURSE -60 TURN
        RECURSE 120 TURN
        RECURSE -60 TURN
        RECURSE
        -1 DEPTH +!
    THEN
;

: SNOWFLAKE MAXDEPTH ! PENUP 0 159 MOVETO 0 TURNTO PENDOWN 1 DEPTH ! TRIEDGE ;

SHOW SPIN RESET SPIRAL RESET ZOOM
0 CLEARTO 3 HGRCOLOR
1 SNOWFLAKE
2 SNOWFLAKE
3 SNOWFLAKE
4 SNOWFLAKE
5 SNOWFLAKE
