public class Turtle
extends java.lang.Object
implements java.lang.Cloneable
Turtle
, cf. the
Java Turtle Package description.Constructor and Description |
---|
Turtle()
Create a new
Turtle |
Modifier and Type | Method and Description |
---|---|
java.awt.geom.Point2D.Double |
_getPos()
Query the
Turtle 's position without wrapping. |
double |
_getX()
Query the
Turtle 's x-position without wrapping. |
double |
_getY()
Query the
Turtle 's y-position without wrapping. |
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 |
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).
|
void |
back(double distance)
Same as bk(double distance).
|
void |
beep()
Emit a beep.
|
void |
bk(double distance)
Move the
Turtle backwards. |
void |
bong()
Emit a 'bong' via the sound card.
|
void |
clean()
Erase all traces and text painted by the turtles, but let all
turtles where they are.
|
void |
clear()
Clear the Turtle's playground.
|
void |
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.
|
void |
enableRepaint(boolean b)
Enable/disable automatic repainting.
|
void |
fd(double distance)
Move the
Turtle forwards. |
void |
fill()
Fill the region the Turtle is in.
|
void |
fill(double x,
double y)
Fill the region as if the Turtle where at coordinates
x and y . |
void |
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.
|
Pen |
getPen()
Get the
Turtle 's Pen . |
java.awt.Color |
getPixelColor()
Return the color of the pixel at the current turtle position.
|
Playground |
getPlayground()
Get the
Playground . |
java.awt.geom.Point2D.Double |
getPos()
Query the
Turtle 's position |
double |
getSpeed()
Get the current speed.
|
ch.aplu.turtle.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. |
void |
hideTurtle()
Hide the
Turtle . |
void |
home()
Move the Turtle back "home", i.e. set its position
to the origin, facing NORTH.
|
void |
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. |
void |
label(java.lang.String text)
Paint the specified text at the current turtle position.
|
void |
left(double degrees)
Same as lt(double degrees)
|
void |
leftCircle(double radius)
Draw a circle to the left from the current position with
turtle's heading tangent direction and given radius.
|
void |
lt(double degrees)
Turn the
Turtle the given angle (in degrees) to the left |
void |
pd()
Lowers the
Turtle 's pen down so it
will draw a line when moving. |
void |
pe()
The
Turtle 's Pen is
changed to an eraser (which is in fact a pen with
background color). |
void |
penDown()
Lower the
Turtle 's Pen down so it
will draw a line when moving. |
void |
penErase()
The
Turtle 's Pen is
changed to an eraser (which is in fact a pen with
background color). |
void |
penUp()
Lift the
Turtle 's pen up so it
won't draw a line anymore. |
int |
penWidth()
Query the pen width.
|
void |
penWidth(int newWidth)
Set the pen width.
|
boolean |
print(TPrintable tp)
Same as print(tp, 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.
|
void |
pu()
Lift the
Turtle 's pen up so it
won't draw a line anymore. |
void |
repaint()
Perform manual repainting when automatic repainting is
disabled.
|
void |
right(double degrees)
Same as rt(double degrees).
|
void |
rightCircle(double radius)
Draw a circle to the right from the current position with
turtle's heading tangent direction and given radius.
|
void |
rt(double degrees)
Turn the
Turtle the given angle (in degrees) to the right. |
void |
setAngle(int angle)
Sets angle of the turtle.
|
void |
setAngleResolution(int newResolution)
Set the angle resolution for the
Turtle 's pictures. |
void |
setBounds(int x,
int y,
int b,
int h)
Transforms the gui-position to mouse-coordinates.
|
void |
setClip(boolean clip)
Sets clipping-mode on/off.
|
void |
setColor(java.awt.Color color)
Set the
Turtle 's color to the specified one. |
void |
setFillColor(java.awt.Color color)
Set the color to the specified one.
|
void |
setFont(java.awt.Font font)
Set the current font as specified.
|
void |
setFont(java.lang.String fontName,
int style,
int size)
Change the current font to the specified one.
|
void |
setFontSize(int size)
Set the font size.
|
void |
setFontStyle(int style)
Set the font style.
|
void |
setH(double degrees)
Set the
Turtle 's heading.
0 means facing NORTH. |
void |
setHeading(double degrees)
This is the same as setH(double degrees).
|
void |
setLineWidth(double lineWidth)
Set the line thickness.
|
void |
setLineWidth(float lineWidth)
Set the line thickness.
|
void |
setPenColor(java.awt.Color color)
Set the
Turtle 's pen color. |
void |
setPenUp(boolean penup)
Sets pen-position up/down.
|
void |
setPlayground(Playground playground)
Set the
Playground to the specified
playground . |
void |
setPos(double x,
double y)
Put the
Turtle to a new position with specified
x- and y-coordinates. |
void |
setPos(java.awt.geom.Point2D.Double p)
Put the
Turtle to a new position. |
void |
setScreenPos(java.awt.Point p)
Put the
Turtle to a new screen position. |
void |
setScreenX(int x)
Put the
Turtle to a new position with the given screen x-coordinates. |
void |
setScreenY(int y)
Put the
Turtle to a new position with the given screen y-coordinates. |
void |
setSpeed(double speed)
Set the
Turtle 's speed. |
void |
setVisible(boolean show)
Shows or hides the turtle.
|
void |
setX(double x)
Put the
Turtle to a new position with the given x-coordinates. |
void |
setY(double y)
Put the
Turtle to a new position with the given y-coordinates. |
void |
showTurtle()
The same as st().
|
static void |
sleep(int time)
Delay execution for the given amount of time ( in ms ).
|
void |
st()
Set the
Turtle to show mode. |
void |
stampTurtle()
Put a Turtle image at the current position.
|
void |
toBottom()
Put this turtle to the bottom.
|
void |
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
|
void |
wrap()
Cause the
Turtle to wrap around the playground borders. |
public java.awt.geom.Point2D.Double toTurtlePos(java.awt.Point p)
public java.awt.geom.Point2D.Double toTurtlePos(int x, int y)
public double toTurtleX(int x)
public double toTurtleY(int y)
public void addMouseListener(java.awt.event.MouseListener l)
public void addMouseMotionListener(java.awt.event.MouseMotionListener l)
public void beep()
bong()
public void bong()
beep()
public void 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).public ch.aplu.turtle.TurtleFactory getTurtleFactory()
TurtleFactory
of this turtle.TurtleFactory
public Playground getPlayground()
Playground
.public void setPlayground(Playground playground)
Playground
to the specified
playground
.
The Turtle
is removed from the old
Playground
and set to the new one.public double getSpeed()
public double _getX()
Turtle
's x-position without wrapping.
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 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 java.awt.geom.Point2D.Double _getPos()
Turtle
's position without wrapping.
Coordinate are not bound to playground even when
wrapping is on.public java.awt.geom.Point2D.Double getPos()
Turtle
's positionpublic void setX(double x)
Turtle
to a new position with the given x-coordinates.public void setScreenX(int x)
Turtle
to a new position with the given screen x-coordinates.public void setY(double y)
Turtle
to a new position with the given y-coordinates.public void setScreenY(int y)
Turtle
to a new position with the given screen y-coordinates.public void ht()
Turtle
.public void hideTurtle()
Turtle
.
This is the same as ht().st()
public void st()
Turtle
to show mode.
That means that the Turtle
will be drawn.ht()
public void showTurtle()
st()
public boolean isHidden()
Turtle
is hidden or not.true
if the Turtle
is hidden,
false
otherwise.public void setHeading(double degrees)
setH(double)
public void setH(double degrees)
Turtle
's heading.
0 means facing NORTH.setHeading(double)
public double heading()
Turtle
's heading.setH(double)
public double heading(double degrees)
Turtle
's heading to the new value.setH(double)
public void setSpeed(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
.fd(double)
,
bk(double)
public void lt(double degrees)
Turtle
the given angle (in degrees) to the leftrt(double)
public void left(double degrees)
lt(double)
public void rt(double degrees)
Turtle
the given angle (in degrees) to the right.rt(double)
public void right(double degrees)
rt(double)
public void forward(double distance)
fd(double)
public void fd(double distance)
Turtle
forwards.
Negative values for distance
are
allowed. In that case, the Turtle
will move backwards.bk(double)
public void back(double distance)
bk(double)
public void bk(double distance)
Turtle
backwards.
Negative values for distance
are
allowed. In that case, the Turtle
will move forwards.fd(double)
public double distance(double x, double y)
public double distance(java.awt.geom.Point2D.Double p)
public void leftCircle(double radius)
public void rightCircle(double radius)
public void penUp()
Turtle
's pen up so it
won't draw a line anymore.
This is the same as pu().public void pu()
Turtle
's pen up so it
won't draw a line anymore.
This is the same as penUp().public void penDown()
Turtle
's Pen
down so it
will draw a line when moving.
This is the same as pd().public void pd()
Turtle
's pen down so it
will draw a line when moving.
This is the same as penDown().public boolean isPenUp()
Pen
's state (up or down).public Pen getPen()
Turtle
's Pen
.
You need it if you want to change end caps etc.Pen
public void setLineWidth(double lineWidth)
public void setLineWidth(float lineWidth)
public void setColor(java.awt.Color color)
Turtle
's color to the specified one.public void setFillColor(java.awt.Color color)
fill()
public java.awt.Color getColor()
Turtle
's current color.public void setPenColor(java.awt.Color color)
Turtle
's pen color.public void home()
public void penErase()
Turtle
's Pen
is
changed to an eraser (which is in fact a pen with
background color).
This is the same as pe()pe()
public void pe()
Turtle
's Pen
is
changed to an eraser (which is in fact a pen with
background color).
This is the same as penErase()penErase()
public void setPos(double x, double y)
Turtle
to a new position with specified
x- and y-coordinates.public void setPos(java.awt.geom.Point2D.Double p)
Turtle
to a new position.public void setScreenPos(java.awt.Point p)
Turtle
to a new screen position.public void stampTurtle()
public double towards(double x, double y)
public double towards(java.awt.geom.Point2D.Double p)
public void toBottom()
public void toTop()
public void penWidth(int newWidth)
public int penWidth()
public void wrap()
Turtle
to wrap around the playground borders.
e.g when as the Turtle
leaves the Window on one side,
it reappears on the opposite side.clip()
public boolean isClip()
Turtle
is in clip mode.public boolean isWrap()
Turtle
is in wrap mode.public void fill()
public void fill(double x, double y)
x
and y
.public void clean()
public void label(java.lang.String text)
public void setFont(java.awt.Font font)
Font
public void setFont(java.lang.String fontName, int style, int size)
getAvailableFontFamilies()
,
more information about fontName, style and size.
public void setFontSize(int size)
changing the font style
,
changing the whole font.
public void 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 static java.lang.String[] getAvailableFontFamilies()
public java.awt.Font getFont()
public java.lang.Object clone()
clone
in class java.lang.Object
public void antiAliasing(boolean on)
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 print(TPrintable tp)
public boolean printScreen(double scale)
public boolean printScreen()
public void clear()
public static void sleep(int time)
public java.lang.String version()
public void enableRepaint(boolean b)
Turtle
speeds up the graphics enormously.public void repaint()
public java.awt.Color getPixelColor()
public void setBounds(int x, int y, int b, int h)
public void setVisible(boolean show)
public void setClip(boolean clip)
public void setPenUp(boolean penup)
public void setAngle(int angle)