Download code

Jump to: navigation, search

Back to Sierpinski_triangle_(Forth)

Download for Windows: single file, zip

Download for UNIX: single file, zip, tar.gz, tar.bz2

sierpinski.f

 1 : ctable   create does> + c@ ;
 2 80 constant size
 3 create state size 1+ allot
 4 
 5 : init-state
 6   state size 1+ erase
 7   1 state size 2/ + c! ;
 8 
 9 ctable symbol  bl c,  char @ c,
10 : .state
11   cr size 0 do
12     state i + c@ symbol emit
13   loop ;
14 
15 \ the input has three bits: b0,b1,b2 = next neighbor, current cell, previous neighbor
16 
17 ctable transition
18 \ 000  001  010  011  100  101  110  111
19    0 c, 1 c, 1 c, 1 c, 1 c, 1 c, 1 c, 0 c,
20 : gen
21   state c@ ( neighborhood )
22   size 0 do
23     2*  state i + 1+ c@ or  7 and
24     dup transition state i + c!
25   loop drop ;
26 : sierpinski ( n -- )
27   init-state .state
28   1 ?do gen .state loop ;
29 
30 32 sierpinski bye


hijacker
hijacker
hijacker
hijacker