Start Search Contents Index Links About
Cantor.java
/*
 * Author: Havard Rast Blok
 * E-mail: 
 * Web   : www.rememberjava.com
 */

import java.awt.*;
import javax.swing.*;

/*
 * Draw recursive circles
 */
public class Cantor extends JFrame
{
  public Cantor()
  {
    setDefaultCloseOperationJFrame.EXIT_ON_CLOSE );
    setSize(400400);
    show();
  }
  
  public void paintGraphics g )
  {
    g.setColorColor.white );
    g.fillRect00, getWidth(), getHeight() );
    g.setColorColor.black );

    drawCantor(200200150, Math.PI/27, g);
  }
  
  public void drawCantor(int x, int y, int r, double a, int times, Graphics g)
  {
    System.out.println("x="+x+", y="+y+", r="+r+", times="+times);

    if(times>0)
    {
      drawMidCircle(x, y, r, g);
      drawCantor(x+r/2, y, r/20, times-1, g);
      drawCantor(x-r/2, y, r/20, times-1, g);
    }
  }
  

  public void drawMidCircle(int x, int y, int r, Graphics g)
  {
    g.drawOval(x-r, y-r, 2*r, 2*r);
  }

  public static void mainString args[] )
  {
    new Cantor();
  }


}


site: Håvard Rast Blok
mail:
updated: 27 July 2007