/* Another pre-Mandelbrot classic, this one found by W. Sierpinski around * World War I. It is generated by dividing a triangle into four congruent * smaller triangles, doing the same to each of them, and so on, even * unto infinity (in our case, 'max'). * If you think of the interior triangles as "holes", they occupy more and * more of the total area, while the "solid" portion becomes hopelessly * fragile. * C.A. Bertulani, 07/21/2000 */ import java.awt.*; import java.applet.*; public class Sierpin extends Applet { public void Sierplot(Graphics g) /* plot method */ { int i,max; double x, y, r; double a1,a2,a3,b1,b2,b3; max=80000; /* maximum number of iterations */ // set width, height and positions within gasket a1=20; b1=360; a2=320; b2=360; a3=170; b3=100; // starting point - center x = 180.; y = 150.; // graphics setBackground(Color.black); g.setColor(Color.yellow); // draw the gasket for(i=1 ; i<=max ; i++) { r = Math.random(); /* generate random number in interval (0-1) */ if (r <= 0.3333) { x = 0.5*(x + a1); y = 0.5*(y + b1); } else if(r > 0.3333 && r <= 0.6666) { x = 0.5*(x + a2); y = 0.5*(y + b2); } else { x = 0.5*(x + a3); y = 0.5*(y + b3); } // Draws a line, using the current color, between the points (x1, y1) // and (x2, y2) in this graphics context's coordinate system. // Here it just draws a point g.drawLine((int)x,(int)y,(int)x,(int)y); } } public void paint(Graphics g) { Sierplot(g); } }