Class SimpleTurtle

java.lang.Object
  extended by SimpleTurtle
Direct Known Subclasses:
Turtle

public class SimpleTurtle
extends java.lang.Object

Class that represents a Logo-style turtle. The turtle starts off facing north. A turtle can have a name, has a starting x and y position, has a heading, has a width, has a height, has a visible flag, has a body color, can have a shell color, and has a pen. You can display this turtle in either a picture or in a class that implements ModelDisplay. Copyright Georgia Institute of Technology 2004

Author:
Barb Ericson ericson@cc.gatech.edu

Constructor Summary
SimpleTurtle(int x, int y)
          Constructor that takes the x and y position for the turtle
SimpleTurtle(int x, int y, ModelDisplay display)
          Constructor that takes the x and y position and the model displayer
SimpleTurtle(int x, int y, Picture picture)
          Constructor that takes the x and y position and the picture to draw on
SimpleTurtle(ModelDisplay display)
          Constructor that takes a model display and adds a turtle in the middle of it
SimpleTurtle(Picture picture)
          Constructor that takes the picture to draw on and will appear in the middle
 
Method Summary
 void drawInfoString(java.awt.Graphics g)
          Method to draw the information string
 void drop(Picture dropPicture)
          Method to draw a passed picture at the current turtle location and rotation
 void forward(int pixels)
          Method to move the turtle forward the given number of pixels
 java.awt.Color getBodyColor()
          Method to get the body color
 int getHeading()
          Method to get the current heading
 java.awt.Color getInfoColor()
          Method to get the information color
 java.lang.String getName()
          Method to get the name of the turtle
 Pen getPen()
          Method to get the pen from the turtle
 java.awt.Color getPenColor()
          Method to get the pen color
 int getPenWidth()
          Method to get the pen width
 java.awt.Color getShellColor()
          Method to get the shell color
 boolean getShowInfo()
          Method to get value of show info
 int getXPos()
          Method to get the current x position
 int getYPos()
          Method to get the current y position
 boolean isPenDown()
          Method to check if the pen is down
 boolean isVisible()
          Method to get the value of the visible flag
 void moveTo(int x, int y)
          Method to move to turtle to the given x and y location
 void paintComponent(java.awt.Graphics g)
          Method to paint the turtle
 void setBodyColor(java.awt.Color color)
          Method to set the body color
 void setHeading(int heading)
          Method to set the heading
 void setInfoColor(java.awt.Color color)
          Method to set the information color
 void setName(java.lang.String name)
          Method to set the name of the turtle
 void setPen(Pen pen)
          Method to set the pen for this turtle
 void setPenColor(java.awt.Color color)
          Method to set the pen color
 void setPenDown(boolean value)
          Method to set the pen down boolean variable
 void setPenWidth(int width)
          Method to set the pen width
 void setShellColor(java.awt.Color color)
          Method to set the shell color
 void setShowInfo(boolean value)
          Method to show the turtle information string
 void setVisible(boolean value)
          Method to set the visible flag
 java.lang.String toString()
          Method to return a string with informaiton about this turtle
 void turn(int degrees)
          Method to turn the turtle the passed degrees use negative to turn left and pos to turn right
 void turnLeft()
          Method to turn left
 void turnRight()
          Method to turn right
 void updateDisplay()
          Method to update the display of this turtle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

SimpleTurtle

public SimpleTurtle(int x,
                    int y)
Constructor that takes the x and y position for the turtle

Parameters:
x - the x pos
y - the y pos

SimpleTurtle

public SimpleTurtle(int x,
                    int y,
                    ModelDisplay display)
Constructor that takes the x and y position and the model displayer

Parameters:
x - the x pos
y - the y pos
display - the model display

SimpleTurtle

public SimpleTurtle(ModelDisplay display)
Constructor that takes a model display and adds a turtle in the middle of it

Parameters:
display - the model display

SimpleTurtle

public SimpleTurtle(int x,
                    int y,
                    Picture picture)
Constructor that takes the x and y position and the picture to draw on

Parameters:
x - the x pos
y - the y pos
picture - the picture to draw on

SimpleTurtle

public SimpleTurtle(Picture picture)
Constructor that takes the picture to draw on and will appear in the middle

Parameters:
picture - the picture to draw on
Method Detail

getShowInfo

public boolean getShowInfo()
Method to get value of show info

Returns:
true if should show info, else false

setShowInfo

public void setShowInfo(boolean value)
Method to show the turtle information string

Parameters:
value - the value to set showInfo to

getShellColor

public java.awt.Color getShellColor()
Method to get the shell color

Returns:
the shell color

setShellColor

public void setShellColor(java.awt.Color color)
Method to set the shell color

Parameters:
color - the color to use

getBodyColor

public java.awt.Color getBodyColor()
Method to get the body color

Returns:
the body color

setBodyColor

public void setBodyColor(java.awt.Color color)
Method to set the body color

Parameters:
color - the color to use

getInfoColor

public java.awt.Color getInfoColor()
Method to get the information color

Returns:
the color of the information string

setInfoColor

public void setInfoColor(java.awt.Color color)
Method to set the information color

Parameters:
color - the new color to use

getXPos

public int getXPos()
Method to get the current x position

Returns:
the x position (in pixels)

getYPos

public int getYPos()
Method to get the current y position

Returns:
the y position (in pixels)

isPenDown

public boolean isPenDown()
Method to check if the pen is down

Returns:
true if down else false

setPenDown

public void setPenDown(boolean value)
Method to set the pen down boolean variable

Parameters:
value - the value to set it to

getPenColor

public java.awt.Color getPenColor()
Method to get the pen color

Returns:
the pen color

setPenColor

public void setPenColor(java.awt.Color color)
Method to set the pen color

Parameters:
color - the color for the pen ink

setPenWidth

public void setPenWidth(int width)
Method to set the pen width

Parameters:
width - the width to use in pixels

getPenWidth

public int getPenWidth()
Method to get the pen width

Returns:
the width of the pen in pixels

getPen

public Pen getPen()
Method to get the pen from the turtle

Returns:
the pen used by this turtle

setPen

public void setPen(Pen pen)
Method to set the pen for this turtle

Parameters:
pen - the pen to use

getHeading

public int getHeading()
Method to get the current heading

Returns:
the heading in degrees

setHeading

public void setHeading(int heading)
Method to set the heading

Parameters:
heading - the new heading to use

getName

public java.lang.String getName()
Method to get the name of the turtle

Returns:
the name of this turtle

setName

public void setName(java.lang.String name)
Method to set the name of the turtle

Parameters:
name - the new name to use

isVisible

public boolean isVisible()
Method to get the value of the visible flag

Returns:
true if visible else false

setVisible

public void setVisible(boolean value)
Method to set the visible flag

Parameters:
value - the value to set it to

updateDisplay

public void updateDisplay()
Method to update the display of this turtle


forward

public void forward(int pixels)
Method to move the turtle forward the given number of pixels

Parameters:
pixels - the number of pixels to walk forward in the heading direction

moveTo

public void moveTo(int x,
                   int y)
Method to move to turtle to the given x and y location


turnLeft

public void turnLeft()
Method to turn left


turnRight

public void turnRight()
Method to turn right


turn

public void turn(int degrees)
Method to turn the turtle the passed degrees use negative to turn left and pos to turn right

Parameters:
degrees - the amount to turn in degrees

drop

public void drop(Picture dropPicture)
Method to draw a passed picture at the current turtle location and rotation

Parameters:
dropPicture - the picture to drop

paintComponent

public void paintComponent(java.awt.Graphics g)
Method to paint the turtle


drawInfoString

public void drawInfoString(java.awt.Graphics g)
Method to draw the information string

Parameters:
g - the graphics context

toString

public java.lang.String toString()
Method to return a string with informaiton about this turtle

Overrides:
toString in class java.lang.Object