intro.ex1
Class IntroTurtle

java.lang.Object
  extended by intro.ex1.IntroTurtle

public class IntroTurtle
extends java.lang.Object

Once instantiated, an object of this class opens a window with black background and a white turtle.

The turtle has an imaginary pen. When the pen is down and the turtle moves, it leaves a trace on the window.
You can move the turtle, set the pen properties (width, color, up/down) and show/hide the turtle using the class's methods.

The class uses code written by Guy Haas for a java course in BFOIT.

Author:
Yoav Wald

Constructor Summary
IntroTurtle()
          Instantiates a new IntroTurtle.
 
Method Summary
 void back(int steps)
          Moves the turtle backward by the given amount of steps.
 void forward(int steps)
          Moves the turtle forward by the given amount of steps.
 void hideTurtle()
          Makes the turtle invisible.
 void left(int degrees)
          Rotates the turtle to the left by the given number of degrees.
 void penDown()
          Puts the pen down.
 void penUp()
          Lifts the pen up.
 void right(int degrees)
          Rotates the turtle to the right by the given number of degrees.
 void setPenColor(int colorNumber)
          Sets the color of the turtle's pen according to the supplied number.
 void setPenSize(int width)
          Sets the turtle's pen size to the supplied width.
 void showTurtle()
          Makes the turtle visible.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

IntroTurtle

public IntroTurtle()
Instantiates a new IntroTurtle. Opens a window with black background and sets the pen color to white.

Method Detail

back

public void back(int steps)
Moves the turtle backward by the given amount of steps. If the pen is down, the turtle will leave a trace where it walked. The color of the trace is set according to the current pen color. If the pen is up, the turtle will move but no trace will be left.

Parameters:
steps - The amount of steps to move the turtle by.

forward

public void forward(int steps)
Moves the turtle forward by the given amount of steps. If the pen is down, the turtle will leave a trace where it walked. The color of the trace is set according to the current pen color. If the pen is up, the turtle will move but no trace will be left.

Parameters:
steps - The amount of steps to move the turtle by.

right

public void right(int degrees)
Rotates the turtle to the right by the given number of degrees.

Parameters:
degrees - the amount of degrees by which the turtle should be rotated.

left

public void left(int degrees)
Rotates the turtle to the left by the given number of degrees.

Parameters:
degrees - the amount of degrees by which the turtle should be rotated.

penUp

public void penUp()
Lifts the pen up. After calling this method, the turtle won't leave a trace where it walks.


penDown

public void penDown()
Puts the pen down. After calling this method, the turtle will leave a trace where it walks.


setPenColor

public void setPenColor(int colorNumber)
Sets the color of the turtle's pen according to the supplied number.

Parameters:
colorNumber - Determines the pen color according to this table:
NumberColorNumberColor
0black8brown
1blue9tan
2green10forest
3cyan11aqua
4red12salmon
5magenta13violet
6yellow14orange
7white15grey

setPenSize

public void setPenSize(int width)
Sets the turtle's pen size to the supplied width. The pen size is the width of the trace left by the turtle after walking while the pen is down.

Parameters:
width - 1 or less gives a single pixel line, each increase enlarges the width by about 2 pixels.

hideTurtle

public void hideTurtle()
Makes the turtle invisible.


showTurtle

public void showTurtle()
Makes the turtle visible.