public class Turtle extends Object implements PaneObject
Modifier and Type | Field and Description |
---|---|
protected String |
referenceIdentification
Reference identification of the instance.
|
Constructor and Description |
---|
Turtle()
Constructs new turtle.
|
Turtle(double x,
double y)
Constructs new turtle at a given position.
|
Turtle(double x,
double y,
String name)
Constructs new turtle at a given position and with a given name.
|
Modifier and Type | Method and Description |
---|---|
void |
center()
Changes turtle's position to the center of the parent pane.
|
void |
circle(double radius)
Paints a circle with specified radius.
|
void |
closePolygon()
Stops collecting the points of a polygon and paints a filled polygon
whose border are determined by collected points.
|
boolean |
containsInShape(double x,
double y)
Returns whether the given point is a point on the turtle's shape.
|
double |
directionTowards(double x,
double y)
Computes the direction towards the specified location.
|
double |
directionTowards(Point2D point)
Computes the direction towards the specified location.
|
double |
distanceTo(double x,
double y)
Computes distance from turtle to the specified location.
|
double |
distanceTo(Point2D point)
Computes distance from turtle to the specified location.
|
void |
dot(double radius)
Paints a filled circle with specified radius.
|
double |
getDirection()
Returns the current direction of the turtle.
|
Color |
getFillColor()
Gets the color used to fill polygons.
|
Font |
getFont()
Gets the font used by the turtle for drawing strings.
|
int |
getFrameCount()
Returns the number of animation frames in the current turtle shape.
|
long |
getFrameDuration()
Returns the frame duration in milliseconds, i.e., the period between two
changes of animation frames for shapes with multiple frames.
|
int |
getFrameIndex()
Returns the index of the current animation frame of the turtle's shape
view.
|
double |
getMoveTurnSpeed()
Returns the speed of move and turn actions.
|
String |
getName()
Gets the turle's name.
|
Pane |
getPane()
Gets the pane to which this turtle belongs.
|
Color |
getPenColor()
Gets the current color of the turtle's pen.
|
double |
getPenWidth()
Gets the current width of the turtle's pen.
|
Point2D |
getPosition()
Returns the current position of the turtle.
|
Rectangle2D |
getRange()
Gets the turtle's range.
|
RangeStyle |
getRangeStyle()
Gets the range style.
|
double |
getScale()
Returns the shape scale.
|
TurtleShape |
getShape()
Gets the current shape of the turtle.
|
int |
getTextHeight()
Returns height of the current turtle's font.
|
double |
getTransparency()
Gets the current transparency of the turtle's shape.
|
int |
getViewCount()
Returns the number of views in the current turtle shape.
|
int |
getViewIndex()
Returns the index of the current view of the turtle shape.
|
double |
getX()
Gets the current x-coordinate of the turtle's position.
|
double |
getY()
Gets the current y-coordinate of the turtle's position.
|
protected void |
invalidateParent()
Calls invalidate method of the parent pane.
|
boolean |
isPenDown()
Gets whether turtle's pen is down.
|
boolean |
isPolygonOpen()
Gets whether the turtle is currently collecting points for drawing a
filled polygon.
|
boolean |
isShapeAnimation()
Returns whether automatic animation of shapes is enabled.
|
boolean |
isViewBoundToDirection()
Returns whether view on shape is bound to turtle's direction.
|
boolean |
isVisible()
Gets whether the turtle (turtle's shape) is visible.
|
void |
moveTo(double x,
double y)
Moves the turtle to new position.
|
void |
moveTo(Point2D point)
Moves the turtle to new position.
|
void |
openPolygon()
Starts collecting the points of a polygon.
|
void |
paintToPaneGraphics(Graphics2D g)
Paints the shape of turtle to a graphics at position relative to parent's
coordinate system.
|
void |
penDown()
Sets the turtle's pen down.
|
void |
penUp()
Sets the turtle's pen up.
|
void |
print(String message)
Prints a text at turtle's position and in the turtle's direction.
|
void |
printCenter(String message)
Prints centered text at turtle's position and in the turtle's direction.
|
void |
setDirection(double direction)
Sets the direction of the turtle.
|
void |
setDirectionTowards(double x,
double y)
Sets direction of the turtle towards the specified location.
|
void |
setDirectionTowards(Point2D point)
Sets direction of the turtle towards the specified location.
|
void |
setFillColor(Color fillColor)
Sets the color used to fill polygons.
|
void |
setFont(Font font)
Sets the font used by the turtle for drawing strings.
|
void |
setFrameDuration(long frameDuration)
Sets the frame duration in milliseconds, i.e., the period between two
changes of consecutive animation frames of the shape with multiple
frames.
|
void |
setFrameIndex(int frameIndex)
Sets the index of the current animation frame of the turtle's shape view.
|
void |
setMoveTurnSpeed(double moveTurnSpeed)
Sets the speed of move and turn actions.
|
void |
setName(String name)
Sets the turtle's name.
|
void |
setPane(Pane newParentPane)
Sets the parent pane, i.e., the containing pane.
|
void |
setPenColor(Color penColor)
Sets the color of the turtle's pen.
|
void |
setPenDown(boolean penDownState)
Sets the state of the turtle's pen.
|
void |
setPenWidth(double penWidth)
Sets width of the turtle's pen.
|
void |
setPosition(double x,
double y)
Sets the position of the turtle.
|
void |
setPosition(Point2D point)
Sets the position of the turtle.
|
void |
setRange(Rectangle2D range)
Sets the turtle's range.
|
void |
setRangeStyle(RangeStyle rangeStyle)
Sets the range style.
|
void |
setScale(double scale)
Sets the shape scale.
|
void |
setShape(TurtleShape shape)
Sets new turtle's shape.
|
void |
setShapeAnimation(boolean enabled)
Sets the state of automatic animation of shapes.
|
void |
setTransparency(double transparency)
Sets the turtles's shape transparency.
|
void |
setViewBoundToDirection(boolean bound)
Sets whether view on shape is bound to turtle's direction.
|
void |
setViewIndex(int viewIndex)
Sets the index of the current view of the turtle shape.
|
void |
setVisible(boolean visible)
Sets the visibility of the turtle.
|
void |
setX(double x)
Sets x-coordinate of the turtle's position.
|
void |
setY(double y)
Sets the y-coordinate of the turtle's position.
|
void |
stamp()
Paints the shape to the parent pane.
|
void |
step(double length)
Moves the turtle in the current direction.
|
int |
textWidth(String message)
Returns width of the message in pixels after printing this message using
current turtle's font.
|
String |
toString() |
void |
turn(double angle)
Turns the turtle in a clockwise direction.
|
void |
turnTowards(double x,
double y)
Turns this turtle towards the specified location.
|
void |
turnTowards(Point2D point)
Turns this turtle towards the specified location.
|
protected final String referenceIdentification
public Turtle()
public Turtle(double x, double y)
x
- the X-coordinate of the turtle's position.y
- the Y-coordinate of the turtle's position.public Turtle(double x, double y, String name)
x
- the X-coordinate of the turtle's position.y
- the Y-coordinate of the turtle's position.name
- the name for the turtle.public double getX()
public void setX(double x)
x
- the desired x-coordinate.public double getY()
public void setY(double y)
y
- the desired y-coordinate.public double getDirection()
public void setDirection(double direction)
direction
- the desired direction of the turtle in degrees.public double getPenWidth()
public void setPenWidth(double penWidth)
penWidth
- the desired width of the turtle's pen. In case of a negative
value, the value 0 is set.public Color getPenColor()
public void setPenColor(Color penColor)
penColor
- the desired pen color.NullPointerException
- if the desired pen color is null.public boolean isPenDown()
public void setPenDown(boolean penDownState)
penDownState
- true for turtle's pen down, false otherwise.public boolean isVisible()
public void setVisible(boolean visible)
visible
- true for visible turtle, false for invisible turlepublic TurtleShape getShape()
public void setShape(TurtleShape shape)
shape
- the desired shape of the turtle. If set to null, the default
turtle shape is used.public double getTransparency()
public void setTransparency(double transparency)
transparency
- the desired shape transparency. If it is a number smaller than
0, the value 0 is set. If it is a number greater than 1, the
value 1 is set.public void setScale(double scale)
scale
- the desired shape scale.public double getScale()
public String getName()
public void setName(String name)
name
- the desired turtle name (String or null).public Font getFont()
public void setFont(Font font)
font
- the desired fontpublic boolean isPolygonOpen()
public RangeStyle getRangeStyle()
public void setRangeStyle(RangeStyle rangeStyle)
rangeStyle
- the desired range style.public Rectangle2D getRange()
public void setRange(Rectangle2D range)
range
- the desired range rectangle or null if the range is determined
by the parent pane.public Color getFillColor()
public void setFillColor(Color fillColor)
fillColor
- the desired fill color.NullPointerException
- if the color is set to null.public void setMoveTurnSpeed(double moveTurnSpeed)
moveTurnSpeed
- the speed of move and turn actions (smaller is faster), the
value 0 disabled animations during turn and move/step actions.public double getMoveTurnSpeed()
setMoveTurnSpeed(double)
public void turn(double angle)
angle
- angle in degrees.public void setPosition(Point2D point)
point
- the desired location.public void setPosition(double x, double y)
x
- the X-coordinate of the desired turtle position.y
- the Y-coordinate of the desired turtle position.public Point2D getPosition()
public void center()
public void penDown()
public void penUp()
public void moveTo(double x, double y)
x
- the X-coordinate of the target position.y
- the Y-coordinate of the target position.public void moveTo(Point2D point)
point
- the target position.public void step(double length)
length
- the length of the step.public double distanceTo(double x, double y)
x
- the x-coordinate of the location.y
- the y-coordinate of the location.public double distanceTo(Point2D point)
point
- the location.public double directionTowards(double x, double y)
x
- the x-coordinate of the location.y
- the y-coordinate of the location.public double directionTowards(Point2D point)
point
- the location.public void turnTowards(Point2D point)
point
- the location.public void turnTowards(double x, double y)
x
- the X-coordinate of the location.y
- the Y-coordinate of the location.public void setDirectionTowards(double x, double y)
x
- the X-coordinate of the location.y
- the Y-coordinate of the location.public void setDirectionTowards(Point2D point)
point
- the location.public void print(String message)
message
- the message to be printed.public void printCenter(String message)
message
- the message to be printed.public int textWidth(String message)
message
- the message.public int getTextHeight()
public void openPolygon()
public void closePolygon()
public void dot(double radius)
radius
- the radius of the circle.public void circle(double radius)
radius
- the radius of the circle.public void stamp()
public void paintToPaneGraphics(Graphics2D g)
paintToPaneGraphics
in interface PaneObject
g
- the graphics where the content is drawn.public Pane getPane()
getPane
in interface PaneObject
public void setPane(Pane newParentPane)
setPane
in interface PaneObject
newParentPane
- the desired parent pane.public boolean isViewBoundToDirection()
public void setViewBoundToDirection(boolean bound)
bound
- desired binding state.public int getViewIndex()
public void setViewIndex(int viewIndex)
viewIndex
- the index of desired view on the turtle shape.public int getViewCount()
public int getFrameIndex()
public void setFrameIndex(int frameIndex)
frameIndex
- the index of desired frame in the current view on the turtle
shape.public int getFrameCount()
public long getFrameDuration()
public void setFrameDuration(long frameDuration)
frameDuration
- the desired frame duration in milliseconds.public boolean isShapeAnimation()
public void setShapeAnimation(boolean enabled)
enabled
- true for enabling automatic animation, false for disabling.public boolean containsInShape(double x, double y)
x
- the x-coordinate of the point.y
- the y-coordinate of the point.protected void invalidateParent()
Copyright © 2017. All rights reserved.