\
\ Prints the Sierpinski gasket.
\ Author: Joshua & Arnold Doray
\ Date: 22 Sept 2017
\
: zero ( xs -- xs ) dup { xs }
xs tuple-len [: { k }
xs 0 k !!
;] itimes
;
158 constant N
0 variable D1
0 variable D2
: print ( xs -- ) { xs }
xs tuple-len [:
xs swap @@
0 <= -> " " |
_ -> "U" |. (.)
;] itimes cr
;
\ ----------------------------------------- Rules
: wrap
dup 0 < -> N + |. N mod
;
: crop { xs c }
N [: { k }
xs k @@ c > -> xs 0 k !! |.
;] itimes
;
: +! ( ts v k -- ) { ts v k }
ts
v ts k @@ +
k !!
;
: move ( xs ys -- ) { xs ys }
N 2 - [: 1+ { k }
xs k @@ { v }
v 0 > if
ys v k 1 - +!
ys v 1+ k +!
ys v k 1 + +!
then
;] itimes
ys 1 crop
;
: switch
D1 @ zero { t }
D2 @ D1 !
t D2 !
;
: iter
[:
D1 @ print
D1 @ D2 @ move switch
;] times
;
: main
N empty-tuple zero D1 !
N empty-tuple zero D2 !
D1 @ 1 65 !!
\ D1 @ 1 130 !!
100 iter
;