/**
 *  PolySpiral draws an outward spiraling polygon-like figure.
 */

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

public class PolySpiral extends Turtle
{


    /**
     *  Main entry point.  Does some setup and calls polySpiral with chosen 
     *  values.
     */
    public void runTurtle()
    {
        setAutoUpdate( false );
        hideTurtle();

        // Try changing the second argument, which is the number of degrees
        // each side is from one another.  Which degree values result in
        // regular patterns?
        polySpiral( 5, 104 );
    }


    /**
     * Spirals outwards by drawing a line of length "sideLength", rotating
     * right through "angle", and then increasing sideLength by 3.  This
     * is repeated 150 times
     */
    private void polySpiral( int sideLength, int angle )
    {
        for ( int i = 0; i < 150; i++ )
        {
            // Set the pen color as a function of which iteration we are on.
            setPenColor( Color.getHSBColor( i / 150f, 1.0f, 1.0f ) );

            forward( sideLength );
            right( angle );
            sideLength = sideLength + 3;
            updateDisplay();
        }
    }


}
