public class SimpleTurtle
extends java.lang.Object
Constructor and Description |
---|
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
|
Modifier and Type | Method and Description |
---|---|
void |
backward()
Method to go backward by 100 pixels
|
void |
backward(int pixels)
Method to go backward a given number of pixels
|
void |
clearPath()
Method to clear the path (history of
where the turtle has been)
|
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 in a picture or model display
|
void |
forward()
Method to move the turtle foward 100 pixels
|
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
|
double |
getDistance(int x,
int y)
Get the distance from the passed x and y location
|
double |
getDistance(SimpleTurtle turtle)
Get the distance from this turtle to another.
|
double |
getHeading()
Method to get the current heading
|
int |
getHeight()
Method to return the height of this object
|
java.awt.Color |
getInfoColor()
Method to get the information color
|
ModelDisplay |
getModelDisplay()
Method to get the model display for this simple turtle
|
java.lang.String |
getName()
Method to get the name of the turtle
|
Pen |
getPen()
Method to get the pen
|
java.awt.Color |
getPenColor()
Method to get the pen color
|
int |
getPenWidth()
Method to get the pen width
|
Picture |
getPicture()
Method to get the picture for this simple turtle
|
java.awt.Color |
getShellColor()
Method to get the shell color
|
boolean |
getShowInfo()
Method to get value of show info
|
int |
getWidth()
Method to return the width of this object
|
int |
getXPos()
Method to get the current x position
|
int |
getYPos()
Method to get the current y position
|
void |
hide()
Method to hide the turtle (stop showing it)
This doesn't affect the pen status
|
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 |
penDown()
Method to set the pen down
|
void |
penUp()
Method to lift the pen up
|
void |
setBodyColor(java.awt.Color color)
Method to set the body color which
will also set the pen color
|
void |
setColor(java.awt.Color color)
Method to set the color of the turtle.
|
void |
setHeading(double heading)
Method to set the heading
|
void |
setHeight(int theHeight)
Method to set the height of this object
|
void |
setInfoColor(java.awt.Color color)
Method to set the information color
|
void |
setModelDisplay(ModelDisplay theModelDisplay)
Method to set the model display for this simple turtle
|
void |
setName(java.lang.String theName)
Method to set the name of the turtle
|
void |
setPen(Pen thePen)
Method to set the pen
|
void |
setPenColor(java.awt.Color color)
Method to set the pen color
|
void |
setPenDown(boolean value)
Method to set the pen down boolean variable
True is down; false is up
|
void |
setPenWidth(int width)
Method to set the pen width
|
void |
setPicture(Picture pict)
Method to set the picture for this simple turtle
|
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.
|
void |
setWidth(int theWidth)
Method to set the width of this object
|
void |
show()
Method to show the turtle (doesn't affect
the pen status
|
java.lang.String |
toString()
Method to return a string with information
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 90 degrees
|
void |
turnRight()
Method to turn right 90 degrees
|
void |
turnToFace(int x,
int y)
Method to turn to face the given x and y
|
void |
turnToFace(SimpleTurtle turtle)
Method to turn to face another simple turtle
|
void |
updateDisplay()
Method to update the display of this turtle and
also check that the turtle is in the bounds
|
public SimpleTurtle(int x, int y)
x
- the x posy
- the y pospublic SimpleTurtle(int x, int y, ModelDisplay display)
x
- the x posy
- the y posdisplay
- the model displaypublic SimpleTurtle(ModelDisplay display)
display
- the model displaypublic SimpleTurtle(int x, int y, Picture picture)
x
- the x posy
- the y pospicture
- the picture to draw onpublic SimpleTurtle(Picture picture)
picture
- the picture to draw onpublic double getDistance(SimpleTurtle turtle)
turtle
- The turtle to compute the distance betwen.public double getDistance(int x, int y)
x
- the x locationy
- the y locationpublic void turnToFace(SimpleTurtle turtle)
turtle
- the turtle turn towardspublic void turnToFace(int x, int y)
x
- the x to turn towardsy
- the y to turn towardspublic Picture getPicture()
public void setPicture(Picture pict)
pict
- the picture to usepublic ModelDisplay getModelDisplay()
public void setModelDisplay(ModelDisplay theModelDisplay)
theModelDisplay
- the model display to usepublic boolean getShowInfo()
public void setShowInfo(boolean value)
value
- the value to set showInfo topublic java.awt.Color getShellColor()
public void setShellColor(java.awt.Color color)
color
- the color to usepublic java.awt.Color getBodyColor()
public void setBodyColor(java.awt.Color color)
color
- the color to usepublic void setColor(java.awt.Color color)
color
- the color to usepublic java.awt.Color getInfoColor()
public void setInfoColor(java.awt.Color color)
color
- the new color to usepublic int getWidth()
public int getHeight()
public void setWidth(int theWidth)
theWidth
- in width in pixelspublic void setHeight(int theHeight)
theHeight
- the height in pixelspublic int getXPos()
public int getYPos()
public Pen getPen()
public void setPen(Pen thePen)
thePen
- the new pen to usepublic boolean isPenDown()
public void setPenDown(boolean value)
value
- the value to set it topublic void penUp()
public void penDown()
public java.awt.Color getPenColor()
public void setPenColor(java.awt.Color color)
color
- the pen colorpublic void setPenWidth(int width)
width
- the width to use in pixelspublic int getPenWidth()
public void clearPath()
public double getHeading()
public void setHeading(double heading)
heading
- the new heading to usepublic java.lang.String getName()
public void setName(java.lang.String theName)
theName
- the new name to usepublic boolean isVisible()
public void hide()
public void show()
public void setVisible(boolean value)
value
- the value to set it topublic void updateDisplay()
public void forward()
public void forward(int pixels)
pixels
- the number of pixels to walk forward in the heading directionpublic void backward()
public void backward(int pixels)
pixels
- the number of pixels to walk backwardpublic void moveTo(int x, int y)
x
- the x value to move toy
- the y value to move topublic void turnLeft()
public void turnRight()
public void turn(int degrees)
degrees
- the amount to turn in degreespublic void drop(Picture dropPicture)
dropPicture
- the picture to droppublic void paintComponent(java.awt.Graphics g)
g
- the graphics context to paint onpublic void drawInfoString(java.awt.Graphics g)
g
- the graphics contextpublic java.lang.String toString()
toString
in class java.lang.Object