'************************************************************** '* One-dimensional cellular automata with rule that * '* generates a Sierpinski triangle * '* ---------------------------------------------------------- * '* Ref.: "Problem Solving with Fortran 90 By David R. Brooks, * '* Springer-Verlag New York, 1997". * '* * '* Basic Release By J-P Moreau, Paris. * '* (www.jpmoreau.fr) * '************************************************************** DEFINT I-N Isize = 60 DIM a(Isize) AS INTEGER 'Boolean DIM olda(Isize) AS INTEGER ' DIM a11 AS INTEGER ' DIM a0 AS INTEGER ' Boolean DIM a1 AS INTEGER ' DIM b(Isize) AS STRING DIM cycle AS INTEGER ncycles = 15 FOR i = 1 TO Isize a(i) = 0 ' 0=False 1=True b(i) = " " NEXT i cycle = 0 a(Isize / 2) = 1 'start with a single live cell b(Isize / 2) = "*" CLS PRINT PRINT " Sierpinski Triangle" PRINT PRINT " Generation "; cycle; FOR i = 1 TO Isize PRINT b(i); NEXT i PRINT ' Generate more cycles FOR i = 1 TO ncycles FOR j = 1 TO Isize olda(j) = a(j) NEXT j FOR j = 2 TO Isize - 1 a11 = olda(j - 1) a0 = olda(j) a1 = olda(j + 1) IF a0 = 0 THEN na0 = 1 ELSE na0 = 0 END IF IF a1 = 0 THEN na1 = 1 ELSE na1 = 0 END IF IF a11 = 0 THEN na11 = 1 ELSE na11 = 0 END IF a(j) = (a11 <> 0 AND na0 <> 0 AND na1 <> 0) OR (na11 <> 0 AND a1 <> 0) NEXT j FOR j = 1 TO Isize IF a(j) <> 0 THEN b(j) = "*" ELSE b(j) = " " END IF NEXT j PRINT " Generation "; i; FOR j = 1 TO Isize PRINT b(j); NEXT j PRINT NEXT i PRINT END