import java.awt.*; import java.applet.*; // copyright, M Paez, 1999, U of Antioquia, r Landau OSU public class Sierpin extends Applet { public void Sierplot(Graphics g) { int i,max; double x, y, r; double a1,a2,a3,b1,b2,b3; max=20000; a1=20; b1=360; a2=320; b2=360; a3=170; b3=100; x = 180.; /* starting point */ y = 150.; setBackground(Color.black); g.setColor(Color.yellow); for(i=1 ; i<=max ; i++) /* draw the gasket */ { r = Math.random(); 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); } g.drawLine((int)x,(int)y,(int)x,(int)y); } } public void paint(Graphics g) { Sierplot(g); } }