|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectch.aplu.turtle.Turtle
public class Turtle
The core class for turtles.
For a simple example on how to use Turtle
, cf. the
Java Turtle Package description.
Field Summary | |
---|---|
static int |
APPLETFRAME
Mode attribute for turtle applets in standalone window |
static int |
STANDARDFRAME
Mode attribute for normal turtle application (default) |
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,
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 . |
|
Turtle(TurtlePane turtlePane)
Create a new Turtle in the given TurtlePane . |
Method Summary | |
---|---|
java.awt.geom.Point2D.Double |
_getPos()
Query the Turtle 's position without wrapping. |
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 |
addStatusBar(int height)
Add a status window attached at the bottom of the game grid window. |
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). |
Turtle |
beep()
Emit a beep. |
Turtle |
bk(double distance)
Move the Turtle backwards. |
Turtle |
bong()
Emit a 'bong' via the sound card. |
Turtle |
clean()
Erase all traces and text painted by the turtles, but let all turtles where they are. |
void |
clear()
Clear the Turtle's playground. |
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. |
void |
enableRepaint(boolean b)
Enable/disable automatic repainting. |
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 as if the Turtle where at 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 . |
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. |
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(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. |
Turtle |
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. |
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 |
setStatusText(java.lang.String text)
Replace the text in the status bar by the given text using the current JOptionPane font and color. |
void |
setStatusText(java.lang.String text,
java.awt.Font font,
java.awt.Color color)
Replace the text in the status bar by the given text using the given font and text color. |
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. |
void |
showStatusBar(boolean show)
Show or hide the status bar. |
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()
Cause the Turtle to wrap around the playground borders. |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static int APPLETFRAME
public static int STANDARDFRAME
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, java.awt.Color color)
Turtle
with specified
color
in its own new window
and the given menu.
public Turtle(TurtleContainer turtleContainer)
Turtle
in the given TurtleContainer
.
public Turtle(TurtlePane turtlePane)
Turtle
in the given TurtlePane
.
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
.
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
.
Method Detail |
---|
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 TurtleFrame getFrame()
public void addMouseListener(java.awt.event.MouseListener l)
public void addMouseMotionListener(java.awt.event.MouseMotionListener l)
public void addKeyListener(java.awt.event.KeyListener l)
public void addWindowListener(java.awt.event.WindowListener l)
public void addWindowFocusListener(java.awt.event.WindowFocusListener l)
public void addComponentListener(java.awt.event.ComponentListener l)
public void addFocusListener(java.awt.event.FocusListener l)
public Turtle beep()
Turtle
to allow chaining.bong()
public Turtle bong()
Turtle
to allow chaining.beep()
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).
public ch.aplu.turtle.TurtleFactory getTurtleFactory()
TurtleFactory
of this turtle.
TurtleFactory
public Playground getPlayground()
Playground
.
public double getSpeed()
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 double getX()
Turtle
's x-position.
If turtle is outside playground and wrapping is on
return the coordinate reduced to the playground.
public double getY()
Turtle
's x-position.
If turtle is outside playground and wrapping is on
return the coordinate reduced to the playground.
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 position
public Turtle setX(double x)
Turtle
to a new position with the given x-coordinates.
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 setY(double y)
Turtle
to a new position with the given y-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 Turtle ht()
Turtle
.
Turtle
to allow chaining.If there is only one turte, the speed is set to -1
so there is no Turtle animation at all.
Hiding the Turtle
speeds up the graphics enormously.
public Turtle hideTurtle()
Turtle
.
This is the same as ht().
Turtle
to allow chaining.st()
public Turtle st()
Turtle
to show mode.
That means that the Turtle
will be drawn.
Turtle
to allow chaining.ht()
public Turtle showTurtle()
Turtle
to allow chaining.st()
public boolean isHidden()
Turtle
is hidden or not.
true
if the Turtle
is hidden,
false
otherwise.public Turtle setHeading(double degrees)
Turtle
to allow chaining.setH(double)
public Turtle setH(double degrees)
Turtle
's heading.
0 means facing NORTH.
Turtle
to allow chaining.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 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 lt(double degrees)
Turtle
the given angle (in degrees) to the left
Turtle
to allow chaining.rt(double)
public Turtle left(double degrees)
Turtle
to allow chaining.lt(double)
public Turtle rt(double degrees)
Turtle
the given angle (in degrees) to the right.
Turtle
to allow chaining.rt(double)
public Turtle right(double degrees)
Turtle
to allow chaining.rt(double)
public Turtle forward(double distance)
Turtle
to allow chaining.fd(double)
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 back(double distance)
Turtle
to allow chaining.bk(double)
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 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 leftCircle(double radius)
Turtle
to allow chaining.public Turtle rightCircle(double radius)
Turtle
to allow chaining.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 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 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 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 boolean isPenUp()
Pen
's state (up or down).
true
if the Pen
is
up, false
otherwise.pu()
,
pd()
public Pen getPen()
Turtle
's Pen
.
You need it if you want to change end caps etc.
Pen
public Turtle setLineWidth(double lineWidth)
clip()
,
wrap()
public Turtle setLineWidth(float lineWidth)
clip()
,
wrap()
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 java.awt.Color getColor()
Turtle
's current color.
public Turtle setPenColor(java.awt.Color color)
Turtle
's pen color.
Turtle
to allow chaining.public Turtle home()
Turtle
to allow chaining.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 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 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 stampTurtle()
Turtle
to allow chaining.public double towards(double x, double y)
public double towards(java.awt.geom.Point2D.Double p)
public Turtle toBottom()
Turtle
to allow chaining.public Turtle toTop()
Turtle
to allow chaining.public Turtle penWidth(int newWidth)
Turtle
to allow chaining.public int penWidth()
public Turtle clip()
Turtle
to clip-mode.
Turtle
to allow chaining.wrap()
,
clip()
public Turtle 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.
Turtle
to allow chaining.clip()
public boolean isClip()
Turtle
is in clip mode.
clip()
,
wrap()
public boolean isWrap()
Turtle
is in wrap mode.
wrap()
,
clip()
public Turtle fill()
Turtle
to allow chaining.public Turtle fill(double x, double y)
x
and y
.
Turtle
to allow chaining.public Turtle clean()
Turtle
to allow chaining.public Turtle label(java.lang.String text)
Turtle
to allow chaining.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 static java.lang.String[] getAvailableFontFamilies()
setFont(java.awt.Font)
,
setFont(java.lang.String, int, int)
public java.awt.Font getFont()
changing the font size
,
changing the font style
,
changing the whole font.
public java.lang.Object clone()
clone
in class java.lang.Object
public Turtle antiAliasing(boolean on)
Turtle
to allow chaining.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 void setTitle(java.lang.String text)
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 addStatusBar(int height)
public void setStatusText(java.lang.String text)
public void setStatusText(java.lang.String text, java.awt.Font font, java.awt.Color color)
public void showStatusBar(boolean show)
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |