import java.awt.Graphics; public class c08_automata extends java.applet.Applet { static final int left = 30; static final int w = 300; static final int n = 2; int c[] = new int[1+w/2]; int lut[] = {1, 0, 0, 1}; public void paint(Graphics g) { LineTo lt = new LineTo(g); for (int x = 1; x <= w/2; x++) { c[x] = 0; } c[7] = 1; c[15] = 1; c[45] = 1; for (int x = 1; x <= w/2; x++) { if (c[x] != 0) { lt.setPixel(2*x+left, 2+left); } } if (n >= 2) { for (int y = 2; y <= w/2; y++) { int c0 = 0; for (int x = 1; x <= w/2; x++) { int c1 = c[x]; c[x] = (c0 + c1) % n; c0 = c1; if (c[x] != 0) { lt.setPixel(2*x+left, 2*y+left); } } } } else { for (int y = 2; y <= w/2; y++) { int c0 = 0; for (int x = 1; x <= w/2; x++) { int c1 = c[x]; c[x] = lut[2*c0 + c1]; c0 = c1; if (c[x] != 0) { lt.setPixel(2*x+left, 2*y+left); } } } } } }