/**
 *  This turtle draws a simple flower on the display using a series of arcs.
 */

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

public class Flower extends Turtle
{

    // The following variables control how the flower is drawn.
    // Try changing them to see the affect.

    private static int NUM_PETALS = 16;		    // Number of petals to draw
    private static int PETAL_ARC_RADIUS = 100;	// Radius of curvature of petal arc
    private static int PETAL_ARC_LEGNTH = 80;	// Length of petal arc in degrees.

    /**
     * Entry point to the Turtle's code.  Sets the pen color and width, 
     * hides the turtle, set autoUpdate false and then calls flower().
     */
    public void runTurtle()
    {
        setPenColor( Color.pink );
        setPenWidth( 2 );
        hideTurtle();
        setAutoUpdate( false );
        flower( NUM_PETALS, PETAL_ARC_RADIUS, PETAL_ARC_LEGNTH );
    }

    /**
     *  Draws an arc to the right.  The arc's radius of curvature is 
     *  specified by "radius" and the amount of curvature is 
     *  specified by "degrees".
     */
    private void arcRight( int radius, int degrees )
    {
        int j = 3;

        for ( int i = 0; i < degrees; i++ )
        {
            forward( radius * 0.0174 );
            right( 1 );
        }
    }


    /**
     *  Draws an arc to the left.  The arc's radius of curvature is 
     *  specified by "radius" and the length of the arc is 
     *  specified by "degrees".
     */
    private void arcLeft( int radius, int degrees )
    {
        for ( int i = 0; i < degrees; i++ )
        {
            forward( radius * 0.0174 );
            left( 1 );
        }
    }


    /**
        *  Draws a single petal with the specified radius and arc length in degrees.
        */
    private void petal( int radius, int degrees )
    {
        arcRight( radius, degrees );
        right( 180 - degrees );
        arcRight( radius, degrees );
        right( 180 - degrees );
        updateDisplay();
        pause( 50 );
    }


    /**
     *  Draws a flower.
     * 
     *  @param numPetals the number of petals
     *	@param petalArcRadius the radious of the arc used for the petals
     *  @param petalArcLength the length of the petal in degrees
     */
    private void flower( int numPetals, int petalArcRadius, int petalArcLength )
    {
        for ( int i = 0; i < numPetals; i++ )
        {
            petal( petalArcRadius, petalArcLength );
            right( 360 / numPetals );
        }
    }


}
