import chess.*;
import java.awt.*;
import java.applet.Applet;
import javax.swing.JFrame;

/**
 * RecursionDemo2.java
 *
 * Created on June 20, 2006, 9:10 AM by Jeremy
 */
public class RecursionDemo2 extends RunnableApplet {
    Screen myScreen;
    Turtle tom;
    
    public void init() {
        myScreen= Chess.newScreen( this );
        tom= myScreen.newTurtle();
        
    } //init
    
    public void run() {
        tom.setPosition(300,600);
        drawCircles( tom, 200 );
        
    } //run

    private void drawCircles(Turtle tom, int size ) {
        if ( size < 1 ) return;
            
        tom.push();
        tom.left(20);        
        tom.forward(size);
        tom.circle(size/4);
        drawCircles( tom, size/2 );
        
        tom.pop();
        tom.push();
        tom.right(20);
        tom.forward(size);
        tom.circle(size/4);
        drawCircles( tom, size/2 );
        tom.pop();
    } // drawCircles    
    
    /**
     *  For testing within NetBeans, we define a main method.  This is
     *  ignored when a web page uses the applet.  Here is the code you should
     *  have in your web page:
     *    <applet archive="CHESS.jar" 
     *         code="RecursionDemo2" width="600" height="400" >
     *    </applet>
     *  The file CHESS.jar is found in the folder "dist", and should be
     *  put next to the html file.
     */
    public static void main( String[] args ) {
        JFrame frame= new JFrame("RecursionDemo2");
        frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
        Applet applet= new RecursionDemo2();
        Dimension appletDimension= new Dimension(600,700);
        applet.setMinimumSize( appletDimension );
        applet.setPreferredSize( appletDimension );
        frame.setContentPane(applet);
        frame.pack();
        frame.setVisible(true);
        applet.init();
        applet.start();
    } //main

} //class
