/**
 *  RandomLines draws a series of random lines on the screen.  This is a 
 *  good example of how to use Java's Random class to construct random numbers.
 */

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

public class RandomLines extends Turtle
{
    // The numLines variable holds how many lines to draw.
    int numLines = 200;

    /**
     *  Main entry point.
     */
    public void runTurtle()
    {
        hideTurtle();
        // Create a random number generator for use below.
        Random rnd = new Random();
        Dimension size = getDisplaySize();

        setPenWidth( 6 );
        int count = 0;
        Console.println( "Drawing " + numLines + " random lines..." );
        while ( count < numLines )
        {
            // Draw a line at a random position and in a random color.
            int x1 = rnd.nextInt( size.width );
            int y1 = rnd.nextInt( size.height );
            int x2 = rnd.nextInt( size.width );
            int y2 = rnd.nextInt( size.height );
            moveTo( x1, y1 );
            setPenColor( new Color( rnd.nextInt( 255 ),
                                    rnd.nextInt( 255 ),
                                    rnd.nextInt( 255 ) ) );
            setPosition( x2, y2 );

            count++;
        }
    }

    /**
     *  A helper method that moves the turtle without drawing anything.
     */
    private void moveTo( int x, int y )
    {
        boolean penWasDown = isPenDown();
        penUp();
        setPosition( x, y );
        if ( penWasDown )
            penDown();
    }


}
