|
||||||||
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 Turtle
, cf. the
Java Turtle Package description.
Constructor Summary | |
Turtle()
Create a new Turtle in its own new window. |
|
Turtle(boolean show)
Create a new Turtle with specified visibility
in its own new window. |
|
Turtle(java.awt.Color color)
Create a new Turtle with specified
color in its own new window. |
|
Turtle(javax.swing.JMenuBar menuBar)
Create a new Turtle in its own new window
and the given menu. |
|
Turtle(javax.swing.JMenuBar menuBar,
boolean show)
Create a new Turtle with specified visibility
in its own new window and the given menu. |
|
Turtle(javax.swing.JMenuBar menuBar,
java.awt.Color color)
Create a new Turtle with specified
color in its own new window
and the given menu. |
|
Turtle(Turtle otherTurtle)
Create a new Turtle in the same
TurtleContainer (window) as
otherTurtle . |
|
Turtle(Turtle otherTurtle,
boolean show)
Create a new Turtle in the same
TurtleContainer (window) as
otherTurtle with specified visibility. |
|
Turtle(Turtle otherTurtle,
java.awt.Color color)
Create a new Turtle with the specified
color in the same
TurtleContainer (window) as otherTurtle . |
|
Turtle(TurtleContainer turtleContainer)
Create a new Turtle in the given TurtleContainer . |
|
Turtle(TurtleContainer turtleContainer,
boolean show)
Create a new Turtle with specified visiblity
in the given TurtleContainer . |
|
Turtle(TurtleContainer turtleContainer,
java.awt.Color color)
Create a new Turtle with specified
color in the given TurtleContainer . |
Method Summary | |
double |
_getX()
Query the Turtle 's x-position.
|
double |
_getY()
Query the Turtle 's y-position without wrapping.
|
void |
addComponentListener(java.awt.event.ComponentListener l)
Add the specified component listener to receive component events. |
void |
addFocusListener(java.awt.event.FocusListener l)
Add the specified focus listener to receive focus events. |
void |
addKeyListener(java.awt.event.KeyListener l)
Add the specified key listener to receive key events. |
void |
addMouseListener(java.awt.event.MouseListener l)
Add the specified mouse listener to receive mouse events. |
void |
addMouseMotionListener(java.awt.event.MouseMotionListener l)
Add the specified mouse motion listener to receive mouse motion events. |
void |
addWindowFocusListener(java.awt.event.WindowFocusListener l)
Add the specified window focus listener to receive window focus events. |
void |
addWindowListener(java.awt.event.WindowListener l)
Add the specified window listener to receive window events. |
Turtle |
antiAliasing(boolean on)
Set antialiasing on or off for the turtle trace buffer This may result in an better image quality, especially for filling operations (platform dependant). |
Turtle |
back(double distance)
Same as bk(double distance). |
void |
beep()
Emit a beep. |
Turtle |
bk(double distance)
Move the Turtle backwards.
|
Turtle |
clean()
Erase all traces and text painted by the turtles. |
Turtle |
clip()
Set the Turtle to clip-mode.
|
java.lang.Object |
clone()
Creates a clone of the Turtle in it's Playground. |
double |
distance(double x,
double y)
Query the distance from the current location to the given one. |
double |
distance(java.awt.geom.Point2D.Double p)
Query the distance from the current location to the given one. |
Turtle |
fd(double distance)
Move the Turtle forwards.
|
Turtle |
fill()
Fill the region the Turtle is in. |
Turtle |
fill(double x,
double y)
Fill the region with coordinates x and y .
|
Turtle |
forward(double distance)
Same as fd(double distance) |
static java.lang.String[] |
getAvailableFontFamilies()
Provide information about all font families (e.g. roman) currently available on your system. |
java.awt.Color |
getColor()
Query the Turtle 's current color. |
java.awt.Font |
getFont()
Return the current font. |
TurtleFrame |
getFrame()
Get the TurtleFrame (derivated from JFrame) |
Pen |
getPen()
Get the Turtle 's Pen .
|
Playground |
getPlayground()
Get the Playground . |
java.awt.geom.Point2D.Double |
getPos()
Query the Turtle 's position |
double |
getSpeed()
Get the current speed. |
TurtleFactory |
getTurtleFactory()
Return the TurtleFactory of this turtle. |
double |
getX()
Query the Turtle 's x-position.
|
double |
getY()
Query the Turtle 's x-position.
|
double |
heading()
Query the Turtle 's heading. |
double |
heading(double degrees)
Set the Turtle 's heading to the new value. |
Turtle |
hideTurtle()
Hide the Turtle .
|
Turtle |
home()
Move the Turtle back "home", i.e. set its position to the origin, facing NORTH. |
Turtle |
ht()
Hide the Turtle . |
boolean |
isClip()
Tell whether the Turtle is in clip mode. |
boolean |
isHidden()
Tell whether the Turtle is hidden or not. |
boolean |
isPenUp()
Query the Pen 's state (up or down). |
boolean |
isWrap()
Tell wheter the Turtle is in wrap mode. |
Turtle |
label(java.lang.String text)
Paint the specified text at the current turtle position. |
Turtle |
left(double degrees)
Same as lt(double degrees) |
Turtle |
leftCircle(double radius)
Draw a circle to the left from the current position with turtle's heading tangent direction and given radius. |
Turtle |
lt(double degrees)
Turn the Turtle the given angle (in degrees) to the left |
Turtle |
pd()
Lowers the Turtle 's pen down so it
will draw a line when moving.
|
Turtle |
pe()
The Turtle 's Pen is
changed to an eraser (which is in fact a pen with
background color).
|
Turtle |
penDown()
Lower the Turtle 's Pen down so it
will draw a line when moving.
|
Turtle |
penErase()
The Turtle 's Pen is
changed to an eraser (which is in fact a pen with
background color).
|
Turtle |
penUp()
Lift the Turtle 's pen up so it
won't draw a line anymore.
|
int |
penWidth()
Query the pen width. |
Turtle |
penWidth(int newWidth)
Set the pen width. |
boolean |
print(TPrintable tp)
Same as print(gp, scale) with scale = 1. |
boolean |
print(TPrintable tp,
double scale)
Print the graphics context to an attached printer with the given magnification scale factor. |
boolean |
printScreen()
Same as printScreen(scale) with scale = 1. |
boolean |
printScreen(double scale)
Print the Turtle's current playground with given scale. |
Turtle |
pu()
Lift the Turtle 's pen up so it
won't draw a line anymore.
|
Turtle |
right(double degrees)
Same as rt(double degrees). |
Turtle |
rightCircle(double radius)
Draw a circle to the right from the current position with turtle's heading tangent direction and given radius. |
Turtle |
rt(double degrees)
Turn the Turtle the given angle (in degrees) to the right. |
Turtle |
setAngleResolution(int newResolution)
Set the angle resolution for the Turtle 's pictures.
|
Turtle |
setColor(java.awt.Color color)
Set the Turtle 's color to the specified one. |
Turtle |
setFillColor(java.awt.Color color)
Set the color to the specified one. |
Turtle |
setFont(java.awt.Font font)
Set the current font as specified. |
Turtle |
setFont(java.lang.String fontName,
int style,
int size)
Change the current font to the specified one. |
Turtle |
setFontSize(int size)
Set the font size. |
Turtle |
setFontStyle(int style)
Set the font style. |
Turtle |
setH(double degrees)
Set the Turtle 's 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(java.awt.Color color)
Set the Turtle 's pen color. |
Turtle |
setPos(double x,
double y)
Put the Turtle to a new position with specified
x- and y-coordinates. |
Turtle |
setPos(java.awt.geom.Point2D.Double p)
Put the Turtle to a new position. |
Turtle |
setScreenPos(java.awt.Point p)
Put the Turtle to a new screen position. |
Turtle |
setScreenX(int x)
Put the Turtle to a new position with the given screen x-coordinates. |
Turtle |
setScreenY(int y)
Put the Turtle to a new position with the given screen y-coordinates. |
void |
setTitle(java.lang.String text)
Set the title of Turtle's playground |
Turtle |
setX(double x)
Put the Turtle to a new position with the given x-coordinates. |
Turtle |
setY(double y)
Put the Turtle to a new position with the given y-coordinates. |
Turtle |
showTurtle()
The same as st(). |
static void |
sleep(int time)
Delay execution for the given amount of time ( in ms ). |
Turtle |
speed(double speed)
Set the Turtle 's speed.
|
Turtle |
st()
Set the Turtle to show mode.
|
Turtle |
stampTurtle()
Put a Turtle image at the current position. |
Turtle |
toBottom()
Put this turtle to the bottom. |
Turtle |
toTop()
Put this turtle to the top. |
java.awt.geom.Point2D.Double |
toTurtlePos(int x,
int y)
Convert from screen coordinates to turtle coordinates |
java.awt.geom.Point2D.Double |
toTurtlePos(java.awt.Point p)
Convert from screen coordinates to turtle coordinates |
double |
toTurtleX(int x)
Convert from screen coordinates to turtle coordinates |
double |
toTurtleY(int y)
Convert from screen coordinates to turtle coordinates |
double |
towards(double x,
double y)
Calculate the direction to a given point. |
double |
towards(java.awt.geom.Point2D.Double p)
Calculate the direction to a given point. |
java.lang.String |
version()
Return version information |
Turtle |
wrap()
Causes the Turtle to wrap around the edges.
|
Methods inherited from class java.lang.Object |
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public Turtle()
Turtle
in its own new window.
public Turtle(boolean show)
Turtle
with specified visibility
in its own new window.
public Turtle(java.awt.Color color)
Turtle
with specified
color
in its own new window.
public Turtle(javax.swing.JMenuBar menuBar)
Turtle
in its own new window
and the given menu.
public Turtle(javax.swing.JMenuBar menuBar, boolean show)
Turtle
with specified visibility
in its own new window and the given menu.
public Turtle(javax.swing.JMenuBar menuBar, java.awt.Color color)
Turtle
with specified
color
in its own new window
and the given menu.
public Turtle(Turtle otherTurtle)
Turtle
in the same
TurtleContainer
(window) as
otherTurtle
.
public Turtle(Turtle otherTurtle, boolean show)
Turtle
in the same
TurtleContainer
(window) as
otherTurtle
with specified visibility.
public Turtle(Turtle otherTurtle, java.awt.Color color)
Turtle
with the specified
color
in the same
TurtleContainer
(window) as otherTurtle
.
public Turtle(TurtleContainer turtleContainer)
Turtle
in the given TurtleContainer
.
public Turtle(TurtleContainer turtleContainer, boolean show)
Turtle
with specified visiblity
in the given TurtleContainer
.
public Turtle(TurtleContainer turtleContainer, java.awt.Color color)
Turtle
with specified
color
in the given TurtleContainer
.
Method Detail |
public double _getX()
Turtle
's x-position.
Coordinate are not bound to playground even when
wrapping is on.
public double _getY()
Turtle
's y-position without wrapping.
Coordinate are not bound to playground even when
wrapping is on.
public void addComponentListener(java.awt.event.ComponentListener l)
public void addFocusListener(java.awt.event.FocusListener l)
public void addKeyListener(java.awt.event.KeyListener l)
public void addMouseListener(java.awt.event.MouseListener l)
public void addMouseMotionListener(java.awt.event.MouseMotionListener l)
public void addWindowFocusListener(java.awt.event.WindowFocusListener l)
public void addWindowListener(java.awt.event.WindowListener l)
public Turtle antiAliasing(boolean on)
Turtle
to allow chaining.public Turtle back(double distance)
Turtle
to allow chaining.bk(double)
public void beep()
public Turtle bk(double distance)
Turtle
backwards.
Negative values for distance
are
allowed. In that case, the Turtle
will move forwards.
Turtle
to allow chaining.fd(double)
public Turtle clean()
Turtle
to allow chaining.public Turtle clip()
Turtle
to clip-mode.
It could be that the Turtle
moves beyond the edge of the window. You won't see it
anymore unless it finds its way back :-)
Turtle
to allow chaining.wrap()
,
#clips()
public java.lang.Object clone()
clone
in class java.lang.Object
public double distance(double x, double y)
Turtle
to allow chaining.public double distance(java.awt.geom.Point2D.Double p)
Turtle
to allow chaining.public Turtle fd(double distance)
Turtle
forwards.
Negative values for distance
are
allowed. In that case, the Turtle
will move backwards.
Turtle
to allow chaining.bk(double)
public Turtle fill()
Turtle
to allow chaining.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.
Turtle
to allow chaining.public Turtle forward(double distance)
Turtle
to allow chaining.fd(double)
public static java.lang.String[] getAvailableFontFamilies()
setFont(java.awt.Font)
,
setFont(java.lang.String, int, int)
public java.awt.Color getColor()
Turtle
's current color.
public java.awt.Font getFont()
changing the font size
,
changing the font style
,
changing the whole font.
public TurtleFrame getFrame()
public Pen getPen()
Turtle
's Pen
.
You need it if you want to change end caps etc.
Pen
public Playground getPlayground()
Playground
.
public java.awt.geom.Point2D.Double getPos()
Turtle
's position
public double getSpeed()
public TurtleFactory getTurtleFactory()
TurtleFactory
of this turtle.
TurtleFactory
public double getX()
Turtle
's x-position.
If turtle is outside playground and wrapping is on
return the coordinate in range -200..200.
public double getY()
Turtle
's x-position.
If turtle is outside playground and wrapping is on
return the coordinate in range -200..200.
public double heading()
Turtle
's heading.
setH(double)
public double heading(double degrees)
Turtle
's heading to the new value.
setH(double)
public Turtle hideTurtle()
Turtle
.
This is the same as ht().
Turtle
to allow chaining.st()
public Turtle home()
Turtle
to allow chaining.#reinit()
public Turtle ht()
Turtle
.
Turtle
to allow chaining.If there is only one turte, the speed is set to -1
so there is no animation at all.
public boolean isClip()
Turtle
is in clip mode.
clip()
,
#wraps()
public boolean isHidden()
Turtle
is hidden or not.
true
if the Turtle
is hidden,
false
otherwise.public boolean isPenUp()
Pen
's state (up or down).
true
if the Pen
is
up, false
otherwise.pu()
,
pd()
public boolean isWrap()
Turtle
is in wrap mode.
wrap()
,
#clips()
public Turtle label(java.lang.String text)
Turtle
to allow chaining.public Turtle left(double degrees)
Turtle
to allow chaining.lt(double)
public Turtle leftCircle(double radius)
Turtle
to allow chaining.public Turtle lt(double degrees)
Turtle
the given angle (in degrees) to the left
Turtle
to allow chaining.rt(double)
public Turtle pd()
Turtle
's pen down so it
will draw a line when moving.
This is the same as penDown().
Turtle
to allow chaining.penDown()
,
penUp()
,
pu()
public Turtle pe()
Turtle
's Pen
is
changed to an eraser (which is in fact a pen with
background color).
This is the same as penErase()
Turtle
to allow chaining.penErase()
public Turtle penDown()
Turtle
's Pen
down so it
will draw a line when moving.
This is the same as pd().
Turtle
to allow chaining.pd()
,
penUp()
,
pu()
public Turtle penErase()
Turtle
's Pen
is
changed to an eraser (which is in fact a pen with
background color).
This is the same as pe()
Turtle
to allow chaining.pe()
public Turtle penUp()
Turtle
's pen up so it
won't draw a line anymore.
This is the same as pu().
Turtle
to allow chaining.pu()
,
penDown()
,
pd()
public int penWidth()
public Turtle penWidth(int newWidth)
Turtle
to allow chaining.public boolean print(TPrintable tp)
public boolean print(TPrintable tp, double scale)
import ch.aplu.turtle.*;
public class PrintTest implements TPrintable
{
private Turtle t = new Turtle();
public PrintTest()
{
draw(); // Draw on screen
t.print(this); // Draw on printer
}
public void draw()
{
t.home(); // Needed for initialization
for (int i = 0; i < 5; i++)
t.fd(20).rt(90).fd(20).lt(90);
}
public static void main(String[] args)
{
new PrintTest();
}
}
public boolean printScreen()
public boolean printScreen(double scale)
public Turtle pu()
Turtle
's pen up so it
won't draw a line anymore.
This is the same as penUp().
Turtle
to allow chaining.penUp()
,
penDown()
,
pd()
public Turtle right(double degrees)
Turtle
to allow chaining.rt(double)
public Turtle rightCircle(double radius)
Turtle
to allow chaining.public Turtle rt(double degrees)
Turtle
the given angle (in degrees) to the right.
Turtle
to allow chaining.rt(double)
public Turtle setAngleResolution(int newResolution)
Turtle
's pictures.
It specifies how many pictures are used. e.g. an angle resolution
of 90 means that you get one picture for every 4 degrees
(= 360/90 degrees).
#DEFAULT_ANGLE_RESOLUTION
public Turtle setColor(java.awt.Color color)
Turtle
's color to the specified one.
Turtle
to allow chaining.public Turtle setFillColor(java.awt.Color color)
Turtle
to allow chaining.fill()
public Turtle setFont(java.awt.Font font)
Turtle
to allow chaining.Font
public Turtle setFont(java.lang.String fontName, int style, int size)
getAvailableFontFamilies()
,
more information about fontName, style and size.
public Turtle setFontSize(int size)
Turtle
to allow chaining.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
Turtle
to allow chaining.changing the font size
,
changing the whole font.
public Turtle setH(double degrees)
Turtle
's heading.
0 means facing NORTH.
Turtle
to allow chaining.setHeading(double)
public Turtle setHeading(double degrees)
Turtle
to allow chaining.setH(double)
public Turtle setLineWidth(double lineWidth)
clip()
,
wrap()
public Turtle setLineWidth(float lineWidth)
clip()
,
wrap()
public Turtle setPenColor(java.awt.Color color)
Turtle
's pen color.
Turtle
to allow chaining.public Turtle setPos(double x, double y)
Turtle
to a new position with specified
x- and y-coordinates.
Turtle
to allow chaining.public Turtle setPos(java.awt.geom.Point2D.Double p)
Turtle
to a new position.
Turtle
to allow chaining.public Turtle setScreenPos(java.awt.Point p)
Turtle
to a new screen position.
Turtle
to allow chaining.public Turtle setScreenX(int x)
Turtle
to a new position with the given screen x-coordinates.
Turtle
to allow chaining.public Turtle setScreenY(int y)
Turtle
to a new position with the given screen y-coordinates.
Turtle
to allow chaining.public void setTitle(java.lang.String text)
public Turtle setX(double x)
Turtle
to a new position with the given x-coordinates.
Turtle
to allow chaining.public Turtle setY(double y)
Turtle
to a new position with the given y-coordinates.
Turtle
to allow chaining.public Turtle showTurtle()
Turtle
to allow chaining.st()
public static void sleep(int time)
public Turtle speed(double speed)
Turtle
's 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
.
Turtle
reference to allow chaining.fd(double)
,
bk(double)
public Turtle st()
Turtle
to show mode.
That means that the Turtle
will be drawn.
Turtle
to allow chaining.ht()
public Turtle stampTurtle()
Turtle
to allow chaining.public Turtle toBottom()
Turtle
to allow chaining.public Turtle toTop()
Turtle
to allow chaining.public java.awt.geom.Point2D.Double toTurtlePos(int x, int y)
public java.awt.geom.Point2D.Double toTurtlePos(java.awt.Point p)
public double toTurtleX(int x)
public double toTurtleY(int y)
public double towards(double x, double y)
public double towards(java.awt.geom.Point2D.Double p)
public java.lang.String version()
public Turtle wrap()
Turtle
to wrap around the edges.
This means: as soon as the Turtle
leaves the Window on one side, it re-
appears on the opposite side.
Turtle
to allow chaining.clip()
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |