import java.awt.Graphics; public class c06_fern extends java.applet.Applet { static final int imax = 10000; static final int left = 30; static final int w = 300; static final int wl = w + left; static final double e1 = 0.5 * w; static final double e2 = 0.57 * w; static final double e3 = 0.408 * w; static final double e4 = 0.1075 * w; static final double f1 = 0 * w; static final double f2 = -0.036 * w; static final double f3 = 0.0893 * w; static final double f4 = 0.27 * w; public void paint(Graphics g) { LineTo lt = new LineTo(g); double x = e1; double y = 0; for (int i = 0; i < imax; i++) { double r = Math.random(); double xn, yn; if (r < 0.02) { xn = 0 * x + 0 * y + e1; yn = 0 * x + 0.27 * y + f1; } else if (r < 0.17) { xn = -0.139 * x + 0.263 * y + e2; yn = 0.246 * x + 0.224 * y + f2; } else if (r < 0.3) { xn = 0.17 * x - 0.215 * y + e3; yn = 0.222 * x + 0.176 * y + f3; } else { xn = 0.781 * x + 0.034 * y + e4; yn = -0.032 * x + 0.739 * y + f4; } lt.setPixel(left+(int)xn, wl-(int)yn); x = xn; y = yn; } } }