/**
 *  Simple turtle that draws a stack of boxes.  Creates a box() method and calls it repeatedly 
 *  to draw the stack.
 */

import java.awt.*;
import javax.swing.*;
import com.otherwise.jurtle.Turtle;

public class BoxesOnBoxes extends Turtle
{

    /**
     *  Main entry point.  After setting things up it calls box() repeatedly.
     */
    public void runTurtle()
    {
        setAutoUpdatePause( 50 );
        setPenColor( Color.magenta );
        int size = 60;
        while ( size > 2 )   // loop while size is bigger than 2
        {
            box( size );
            forward( size );
            size = ( int ) ( size * 0.6 );  // Draw the next box 60% as big.
        }

        hideTurtle();
    }


    /**
     *  Draws a box of the specified size.
     */
    private void box( int size )
    {
        for ( int i = 0; i < 4; i++ )
        {
            forward( size );
            right( 90 );
        }
    }


}
