|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Object | +--ch.aplu.turtle.Turtle
The core class for Turtles.
For a simple example on how to use Turtles, cf. the
Java Turtle Package description.
| Field Summary | |
protected static int |
CLIP
Represents clip mode. |
protected static int |
DEFAULT_ANGLE_RESOLUTION
Represents the default angle resolution. |
protected static int |
DEFAULT_EDGE_BEHAVIOUR
Represents the default edge behaviour (i.e. |
protected static int |
DEFAULT_FRAMES_PER_SECOND
Specifies how many frames per second are used for turtle animation. |
protected static Color |
DEFAULT_PEN_COLOR
Specifies the default pen color. |
protected static double |
DEFAULT_SPEED
Represents the default speed (velocity). |
protected static Color |
DEFAULT_TURTLE_COLOR
Specifies the default turtle color. |
protected static int |
WRAP
Represents wrap mode. |
| Constructor Summary | |
Turtle()
Create a new Turtle in its own new Window. |
|
Turtle(Color color)
Create a new Turtle with specified
color in its own new Window. |
|
Turtle(Turtle otherTurtle)
Create a new Turtle in the same
TurtleContainer (Window) as
otherTurtle |
|
Turtle(Turtle otherTurtle,
Color color)
Create a new Turtle with the specified
color in the same
TurtleContainer (Window) as otherTurtle |
|
Turtle(TurtleContainer turtleContainer)
Create a new Turtle and puts it into the
(already existing) turtleContainer |
|
Turtle(TurtleContainer turtleContainer,
Color color)
Create a new Turtle with specified
color in the specified turtleContainer. |
|
| Method Summary | |
Turtle |
back(double distance)
Same as bk(double distance). |
Turtle |
bk(double distance)
Moves the Turtle backwards.
|
Turtle |
clean()
Clears away all that was painted in some way by a turtle (such as lines, fillings, text, stamps etc.) |
Turtle |
clip()
Set the turtle to clip-mode. |
boolean |
clips()
Tells wheter the turtle is in clip mode. |
protected LineRenderer |
createLineRenderer()
Create a LineRenderer which is responsible
for the correct drawing of the lines. |
protected TurtleFactory |
createTurtleFactory()
Create a TurtleFactory which provides for
the Turtle pictures. |
protected TurtleRenderer |
createTurtleRenderer()
Create a TurtleRenderer which is responsible
for the correct drawing of the Turtle. |
double |
curX()
Query the current x-coordinate. |
double |
curY()
Query the current y-coordinate. |
double |
distance(double x,
double y)
Query the distance from the current location to the given one. |
double |
distance(Point2D.Double p)
Query the distance from the current location to the given one. |
Turtle |
fd(double distance)
Moves the Turtle forwards.
|
Turtle |
fill()
Fills the region the Turtle is in. |
Turtle |
fill(double x,
double y)
Fills the region with coordinates x and y.
|
Turtle |
forward(double distance)
Same as fd(double distance) |
protected int |
getAngleResolution()
Get the angle resolution. |
String[] |
getAvailableFontFamilies()
Provides information about all font families (e.g. |
Color |
getColor()
Query the turtle's current color. |
protected int |
getEdgeBehaviour()
Returns the current edge behaviour. |
Font |
getFont()
Returns the current Font. |
Pen |
getPen()
Get the Turtles Pen.
|
Playground |
getPlayground()
Get the Playground. |
Point2D.Double |
getPos()
Query the turtle's position |
protected Point2D.Double |
getPosition()
|
TurtleFactory |
getTurtleFactory()
Returns the TurtleFactory of this turtle. |
double |
getX()
Query the turtle's x-position. |
double |
getY()
Query the turtle's y-position. |
double |
heading()
Query the Turtles heading. |
double |
heading(double degrees)
Set the Turtles heading to the new value. |
Turtle |
hideTurtle()
Hides the turtle. |
Turtle |
home()
Move the Turtle back "home", i.e. set its position to the origin, facing NORTH. |
Turtle |
ht()
Hides the turtle. |
protected void |
init(Playground playground,
Color color)
Initialize the Turtle.
|
protected void |
init(TurtleContainer turtleContainer,
Color color)
This is only a "meta-method" for calling the init(Playground, Color) method. |
protected void |
internalHide()
This is the method called by the public methods ht() and hideTurtle(). |
protected void |
internalPenErase()
|
protected void |
internalSetPos(double x,
double y)
Set the Turtles Position.
|
protected void |
internalSetX(double x)
Set the Turtles x-Coordinate.
|
protected void |
internalSetY(double y)
Set the Turtles y-Coordinate.
|
boolean |
isHidden()
Tells wheter the Turtle is hidden or not. |
boolean |
isPenUp()
Query the Pens state (up or down). |
Turtle |
label(String text)
Paints the specified Text at the current Turtle position. |
Turtle |
left(double degrees)
Same as lt(double degrees) |
Turtle |
lt(double degrees)
Turns the Turtle degrees degrees to the left. |
Turtle |
pd()
Lowers the Turtles Pen down so it
will draw a line when moving.
|
Turtle |
pe()
The Turtles Pen is
changed to an eraser (which is in fact a pen with
background color).
|
Turtle |
penDown()
Lowers the Turtles Pen down so it
will draw a line when moving.
|
Turtle |
penErase()
The Turtles Pen is
changed to an eraser (which is in fact a pen with
background color).
|
Turtle |
penUp()
Lifts the Turtles Pen up so it
won't draw a line anymore when moving.
|
int |
penWidth()
Query the pen width. |
Turtle |
penWidth(int newWidth)
Set the pen width. |
Turtle |
pu()
Lifts the Turtles Pen up so it
won't draw a line anymore when moving.
|
Turtle |
reinit()
Resets the turtle to its standard settings. |
Turtle |
right(double degrees)
Same as rt(double degrees). |
Turtle |
rt(double degrees)
Turns the Turtle degrees degrees to the right. |
Turtle |
setAngleResolution(int newResolution)
Set the angle resolution for the turtle's pictures. |
Turtle |
setColor(Color color)
Set the turtle's color to the specified one. |
protected void |
setEdgeBehaviour(int edgeBehaviour)
Sets the edge behaviour to the specified value; |
Turtle |
setFillColor(Color color)
Set the fill color to the specified one. |
Turtle |
setFont(Font font)
Sets the current Font to the specified one. |
Turtle |
setFont(String fontName,
int style,
int size)
Change the current font to the specified one. |
Turtle |
setFontSize(int size)
Sets the Font size. |
Turtle |
setFontStyle(int style)
Sets the Font style. |
Turtle |
setH(double degrees)
Set the Turtles heading.
0 means facing NORTH. |
Turtle |
setHeading(double degrees)
This is the same as setH(double degrees). |
Turtle |
setLineWidth(double lineWidth)
Set the Line Thickness. |
Turtle |
setLineWidth(float lineWidth)
Set the Line Thickness. |
Turtle |
setPenColor(Color color)
Set the Turtles Pen color. |
Turtle |
setPos(double x,
double y)
Put the turtle to a new position with specified x- and y-coordinates. |
Turtle |
setPos(Point2D.Double p)
Put the turtle to a new position. |
Turtle |
setX(double x)
Sets the x-coordinate of the Turtles position to the given value. |
Turtle |
setY(double y)
Sets the y-coordinate of the Turtles position to the given value. |
Turtle |
showTurtle()
The same as st(). |
Turtle |
speed(double newSpeed)
Set the Turtles speed.
|
Turtle |
st()
Sets the turtle to show mode. |
Turtle |
stampTurtle()
Leave an imprint of the Turtle on the "canvas". |
Turtle |
toBottom()
Put this turtle to the bottom. |
Turtle |
toTop()
Put this turtle to the top. |
double |
towards(double x,
double y)
Calculates the direction to a given point. |
double |
towards(Point2D.Double p)
Calculates the direction to a given point. |
Turtle |
wrap()
Causes the turtle to wrap around the edges. |
boolean |
wraps()
Tells wheter the turtle is in wrap mode. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
protected static final int CLIP
WRAP,
clip(),
Constant Field Valuesprotected static final int WRAP
CLIP,
wrap(),
Constant Field Valuesprotected static int DEFAULT_EDGE_BEHAVIOUR
CLIP,
WRAP,
clip(),
wrap()protected static double DEFAULT_SPEED
speed(double)protected static int DEFAULT_ANGLE_RESOLUTION
protected static int DEFAULT_FRAMES_PER_SECOND
protected static Color DEFAULT_TURTLE_COLOR
setColor(java.awt.Color)protected static Color DEFAULT_PEN_COLOR
setPenColor(java.awt.Color)| Constructor Detail |
public Turtle()
Turtle in its own new Window.
public Turtle(Color color)
Turtle with specified
color in its own new Window.
public Turtle(TurtleContainer turtleContainer)
Turtle and puts it into the
(already existing) turtleContainer
public Turtle(TurtleContainer turtleContainer,
Color color)
Turtle with specified
color in the specified turtleContainer.
public Turtle(Turtle otherTurtle)
Turtle in the same
TurtleContainer (Window) as
otherTurtle
public Turtle(Turtle otherTurtle,
Color color)
Turtle with the specified
color in the same
TurtleContainer (Window) as otherTurtle
| Method Detail |
protected void init(Playground playground,
Color color)
Turtle.
If you want to inherit from this class and add
new Turtle attributes, you might want to overwrite this method.
protected void init(TurtleContainer turtleContainer,
Color color)
init(Playground, Color)public Turtle reinit()
public Turtle setAngleResolution(int newResolution)
DEFAULT_ANGLE_RESOLUTIONpublic TurtleFactory getTurtleFactory()
TurtleFactory of this turtle.
TurtleFactoryprotected LineRenderer createLineRenderer()
LineRenderer which is responsible
for the correct drawing of the lines.
LineRendererprotected TurtleRenderer createTurtleRenderer()
TurtleRenderer which is responsible
for the correct drawing of the Turtle.
TurtleRendererprotected TurtleFactory createTurtleFactory()
TurtleFactory which provides for
the Turtle pictures.
TurtleFactoryprotected int getAngleResolution()
setAngleResolution(int)public Playground getPlayground()
Playground.
public double getX()
public double getY()
public Point2D.Double getPos()
public Turtle setX(double x)
Turtles position to the given value.
public Turtle setY(double y)
Turtles position to the given value.
protected void internalSetX(double x)
Turtles x-Coordinate.
No repainting!!!
protected void internalSetY(double y)
Turtles y-Coordinate.
No repainting!!!
protected void internalSetPos(double x,
double y)
Turtles Position.
No repainting!!!
public Turtle ht()
st()public Turtle hideTurtle()
st()protected void internalHide()
ht(),
hideTurtle()public Turtle st()
Turtle will be drawn.
ht()public Turtle showTurtle()
st()public boolean isHidden()
Turtle is hidden or not.
true if the turtle is hidden,
false otherwise.public Turtle setHeading(double degrees)
setH(double)public Turtle setH(double degrees)
Turtles heading.
0 means facing NORTH.
setHeading(double)public double heading()
Turtles heading.
setH(double)public double heading(double degrees)
Turtles heading to the new value.
setH(double)public Turtle speed(double newSpeed)
Turtles speed.
If you try to set the speed to 0, it will be set to 1 (very slow).
A negative speed means that moving the turtle (fd, bk)
will not be animated.-1.
fd(double),
bk(double)public Turtle lt(double degrees)
Turtle degrees degrees to the left.
rt(double)public Turtle left(double degrees)
lt(double)public Turtle rt(double degrees)
Turtle degrees degrees to the right.
rt(double)public Turtle right(double degrees)
rt(double)public Turtle forward(double distance)
fd(double)public Turtle fd(double distance)
Turtle forwards.
Negative values for distance are
allowed. In that case, the Turtle
will move backwards.
bk(double)public Turtle back(double distance)
bk(double)public Turtle bk(double distance)
Turtle backwards.
Negative values for distance are
allowed. In that case, the Turtle
will move forwards.
fd(double)protected Point2D.Double getPosition()
public double distance(double x,
double y)
public double distance(Point2D.Double p)
public Turtle penUp()
Turtles Pen up so it
won't draw a line anymore when moving.
This is the same as pu().
pu(),
penDown(),
pd()public Turtle pu()
Turtles Pen up so it
won't draw a line anymore when moving.
This is the same as penUp().
penUp(),
penDown(),
pd()public Turtle penDown()
Turtles Pen down so it
will draw a line when moving.
This is the same as pd().
pd(),
penUp(),
pu()public Turtle pd()
Turtles Pen down so it
will draw a line when moving.
This is the same as penDown().
penDown(),
penUp(),
pu()public boolean isPenUp()
Pens state (up or down).
true if the Pen is
up, false otherwise.pu(),
pd()public Pen getPen()
Turtles Pen.
You need it if you want to change end caps etc.
Penpublic Turtle setLineWidth(double lineWidth)
clip(),
wrap()public Turtle setLineWidth(float lineWidth)
clip(),
wrap()public Turtle setColor(Color color)
public Turtle setFillColor(Color color)
fill()public Color getColor()
public Turtle setPenColor(Color color)
Turtles Pen color.
public Turtle home()
reinit()public Turtle penErase()
Turtles Pen is
changed to an eraser (which is in fact a pen with
background color).
This is the same as pe()
pe()public Turtle pe()
Turtles Pen is
changed to an eraser (which is in fact a pen with
background color).
This is the same as penErase()
penErase()protected void internalPenErase()
public Turtle setPos(double x,
double y)
public Turtle setPos(Point2D.Double p)
public Turtle stampTurtle()
public double towards(double x,
double y)
public double towards(Point2D.Double p)
public double curX()
public double curY()
public Turtle toBottom()
public Turtle toTop()
public Turtle penWidth(int newWidth)
public int penWidth()
protected int getEdgeBehaviour()
CLIP,
WRAPprotected void setEdgeBehaviour(int edgeBehaviour)
CLIP,
WRAPpublic Turtle clip()
wrap(),
clips()public Turtle wrap()
clip()public boolean clips()
clip(),
wraps()public boolean wraps()
wrap(),
clips()public Turtle fill()
public Turtle fill(double x,
double y)
x and y.
A Region is bounded by lines
of any other color than the background color and by the border of
the Window.
public Turtle clean()
public Turtle label(String text)
public Turtle setFont(Font font)
Font
public Turtle setFont(String fontName,
int style,
int size)
getAvailableFontFamilies(),
more information about fontName, style and size.public Turtle setFontSize(int size)
changing the font style,
changing the whole font.public Turtle setFontStyle(int style)
java.awt.Font.PLAIN, java.awt.Font.BOLD, java.awt.Font.ITALIC or java.awt.Font.BOLD+java.awt.Font.ITALIC
changing the font size,
changing the whole font.public String[] getAvailableFontFamilies()
setFont(java.awt.Font),
setFont(java.lang.String, int, int)public Font getFont()
changing the font size,
changing the font style,
changing the whole font.
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||