/************************************************************* * 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". * * * * C++ Release By J-P Moreau, Paris. * * (www.jpmoreau.fr) * *************************************************************/ #include #include #define Size 60 #define TRUE 1 #define FALSE 0 void main() { bool a[Size], old_a[Size]; bool a_1, a0, a1; char b[Size]; int i, j, cycle, n_cycles; // Data n_cycles,a,b /15,Size*.FALSE.,Size*' '/ n_cycles = 15; for (i=1; i<=Size; i++) { a[i]=FALSE; b[i]=' '; } cycle = 0; a[Size / 2] = TRUE; // start with a single live cell b[Size / 2] = '*'; printf("\n Sierpinski Triangle\n\n"); printf(" Generation %2d", cycle); for (i=1; i<=Size; i++) printf("%c", b[i]); printf("\n"); // Generate more cycles for (i=1; i<=n_cycles; i++) { for (j=1; j<=Size; j++) old_a[j] = a[j]; for (j=2; j