/**
 *  The Fireworks turtle draws 25 star bursts on the screen.  The bursts 
 *  are drawn at a random location and in a random color.  A good example of
 *  using the Random class (in the Java class library) to get random integers
 *  and random floating point numbers.
 */

import java.awt.*;
import javax.swing.*;
import com.otherwise.jurtle.*;
import java.util.Random;

public class Fireworks extends Turtle
{
    public void runTurtle()
    {
        setAutoUpdate( false );
        hideTurtle();
        setPenWidth( 1 );

        Random rnd = new Random();

        int numStars = 25;

        for ( int starCount = 1; starCount <= numStars; starCount++ )
        {
            int numLines = rnd.nextInt( 360 );
            double angle = 360.0f / numLines;

            float hue = rnd.nextFloat();
            float saturation = rnd.nextFloat();
            float brightness = rnd.nextFloat();

            Color myColor = Color.getHSBColor( hue, saturation, brightness );
            setPenColor( myColor );


            int xCenter = rnd.nextInt( getDisplaySize().width );
            int yCenter = rnd.nextInt( getDisplaySize().height );

            for ( int i = 1; i <= numLines; i = i + 1 )
            {
                penUp();
                setPosition( xCenter, yCenter );
                penDown();
                forward( rnd.nextInt( 100 ) );
                right( angle );
            }
            pause( 100 );
            updateDisplay();

        }
    }
}
