Class SimpleTurtle
java.lang.Object
SimpleTurtle
- Direct Known Subclasses:
Turtle
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.
The turtle will not go beyond the model display or picture
boundaries.
You can display this turtle in either a picture or in
a class that implements ModelDisplay.
Copyright Georgia Institute of Technology 2004
-
Constructor Summary
ConstructorsConstructorDescriptionSimpleTurtle(int x, int y) Constructor that takes the x and y position for the turtleSimpleTurtle(int x, int y, ModelDisplay display) Constructor that takes the x and y position and the model displayerSimpleTurtle(int x, int y, Picture picture) Constructor that takes the x and y position and the picture to draw onSimpleTurtle(ModelDisplay display) Constructor that takes a model display and adds a turtle in the middle of itSimpleTurtle(Picture picture) Constructor that takes the picture to draw on and will appear in the middle -
Method Summary
Modifier and TypeMethodDescriptionvoidbackward()Method to go backward by 100 pixelsvoidbackward(int pixels) Method to go backward a given number of pixelsvoidMethod to clear the path (history of where the turtle has been)voidMethod to draw the information stringvoidMethod to draw a passed picture at the current turtle location and rotation in a picture or model displayvoidforward()Method to move the turtle foward 100 pixelsvoidforward(int pixels) Method to move the turtle forward the given number of pixelsMethod to get the body colordoublegetDistance(int x, int y) Get the distance from the passed x and y locationdoubleMethod to get the current headingintMethod to return the height of this objectMethod to get the information colorMethod to get the model display for this simple turtlegetName()Method to get the name of the turtlegetPen()Method to get the penMethod to get the pen colorintMethod to get the pen widthMethod to get the picture for this simple turtleMethod to get the shell colorbooleanMethod to get value of show infointgetWidth()Method to return the width of this objectintgetXPos()Method to get the current x positionintgetYPos()Method to get the current y positionvoidhide()Method to hide the turtle (stop showing it) This doesn't affect the pen statusbooleanMethod to check if the pen is downbooleanMethod to get the value of the visible flagvoidmoveTo(int x, int y) Method to move to turtle to the given x and y locationvoidMethod to paint the turtlevoidpenDown()Method to set the pen downvoidpenUp()Method to lift the pen upvoidsetBodyColor(Color color) Method to set the body color which will also set the pen colorvoidMethod to set the color of the turtle.voidsetHeading(double heading) Method to set the headingvoidsetHeight(int theHeight) Method to set the height of this objectvoidsetInfoColor(Color color) Method to set the information colorvoidsetModelDisplay(ModelDisplay theModelDisplay) Method to set the model display for this simple turtlevoidMethod to set the name of the turtlevoidMethod to set the penvoidsetPenColor(Color color) Method to set the pen colorvoidsetPenDown(boolean value) Method to set the pen down boolean variablevoidsetPenWidth(int width) Method to set the pen widthvoidsetPicture(Picture pict) Method to set the picture for this simple turtlevoidsetShellColor(Color color) Method to set the shell colorvoidsetShowInfo(boolean value) Method to show the turtle information stringvoidsetVisible(boolean value) Method to set the visible flagvoidsetWidth(int theWidth) Method to set the width of this objectvoidshow()Method to show the turtle (doesn't affect the pen statustoString()Method to return a string with informaiton about this turtlevoidturn(double degrees) Method to turn the turtle the passed degrees use negative to turn left and pos to turn rightvoidturnLeft()Method to turn leftvoidMethod to turn rightvoidturnToFace(int x, int y) Method to turn towards the given x and yvoidturnToFace(SimpleTurtle turtle) Method to turn to face another simple turtlevoidMethod to update the display of this turtle and also check that the turtle is in the bounds
-
Constructor Details
-
SimpleTurtle
public SimpleTurtle(int x, int y) Constructor that takes the x and y position for the turtle- Parameters:
x- the x posy- the y pos
-
SimpleTurtle
Constructor that takes the x and y position and the model displayer- Parameters:
x- the x posy- the y posdisplay- the model display
-
SimpleTurtle
Constructor that takes a model display and adds a turtle in the middle of it- Parameters:
display- the model display
-
SimpleTurtle
Constructor that takes the x and y position and the picture to draw on- Parameters:
x- the x posy- the y pospicture- the picture to draw on
-
SimpleTurtle
Constructor that takes the picture to draw on and will appear in the middle- Parameters:
picture- the picture to draw on
-
-
Method Details
-
getDistance
public double getDistance(int x, int y) Get the distance from the passed x and y location- Parameters:
x- the x locationy- the y location
-
turnToFace
Method to turn to face another simple turtle -
turnToFace
public void turnToFace(int x, int y) Method to turn towards the given x and y- Parameters:
x- the x to turn towardsy- the y to turn towards
-
getPicture
Method to get the picture for this simple turtle- Returns:
- the picture for this turtle (may be null)
-
setPicture
Method to set the picture for this simple turtle- Parameters:
pict- the picture to use
-
getModelDisplay
Method to get the model display for this simple turtle- Returns:
- the model display if there is one else null
-
setModelDisplay
Method to set the model display for this simple turtle- Parameters:
theModelDisplay- the model display to use
-
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
-
setShellColor
Method to set the shell color- Parameters:
color- the color to use
-
getBodyColor
-
setBodyColor
Method to set the body color which will also set the pen color- Parameters:
color- the color to use
-
setColor
Method to set the color of the turtle. This will set the body color- Parameters:
color- the color to use
-
getInfoColor
Method to get the information color- Returns:
- the color of the information string
-
setInfoColor
Method to set the information color- Parameters:
color- the new color to use
-
getWidth
public int getWidth()Method to return the width of this object- Returns:
- the width in pixels
-
getHeight
public int getHeight()Method to return the height of this object- Returns:
- the height in pixels
-
setWidth
public void setWidth(int theWidth) Method to set the width of this object- Parameters:
theWidth- in width in pixels
-
setHeight
public void setHeight(int theHeight) Method to set the height of this object- Parameters:
theHeight- the height in pixels
-
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)
-
getPen
-
setPen
-
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
-
penUp
public void penUp()Method to lift the pen up -
penDown
public void penDown()Method to set the pen down -
getPenColor
-
setPenColor
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
-
clearPath
public void clearPath()Method to clear the path (history of where the turtle has been) -
getHeading
public double getHeading()Method to get the current heading- Returns:
- the heading in degrees
-
setHeading
public void setHeading(double heading) Method to set the heading- Parameters:
heading- the new heading to use
-
getName
-
setName
Method to set the name of the turtle- Parameters:
theName- the new name to use
-
isVisible
public boolean isVisible()Method to get the value of the visible flag- Returns:
- true if visible else false
-
hide
public void hide()Method to hide the turtle (stop showing it) This doesn't affect the pen status -
show
public void show()Method to show the turtle (doesn't affect the pen status -
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 and also check that the turtle is in the bounds -
forward
public void forward()Method to move the turtle foward 100 pixels -
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
-
backward
public void backward()Method to go backward by 100 pixels -
backward
public void backward(int pixels) Method to go backward a given number of pixels- Parameters:
pixels- the number of pixels to walk backward
-
moveTo
public void moveTo(int x, int y) Method to move to turtle to the given x and y location- Parameters:
x- the x value to move toy- the y value to move to
-
turnLeft
public void turnLeft()Method to turn left -
turnRight
public void turnRight()Method to turn right -
turn
public void turn(double 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
Method to draw a passed picture at the current turtle location and rotation in a picture or model display- Parameters:
dropPicture- the picture to drop
-
paintComponent
Method to paint the turtle- Parameters:
g- the graphics context to paint on
-
drawInfoString
Method to draw the information string- Parameters:
g- the graphics context
-
toString
-