import java.awt.Color;

/* Generate the Sierpinski triangle
 */
public class Chaos {
  
  public static void main(String[] args) {
    
    MyFrame f = new MyFrame("Chaos Game");
    
    double x = 0.4, y = 0.8;
    int k = (int) Math.pow(3, 9);
    
    for (int i=0; i<k; i++) {
      
      int n = (int) Math.floor(3 * Math.random()+1);
      if (n==1) {
        x = 0.5 * (x + 0);
        y = 0.5 * (y + 0);
      } else if (n==2){
        x = 0.5 * (x + 1);
        y = 0.5 * (y + 0);
      } else {
        x = 0.5 * (x + 0.5);
        y = 0.5 * (y + 0.866);
      } 
      
      f.drawPoint(x, y, Color.black);
    }
  }
}
