|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectedu.neu.ccs.pedagogy.Turtle
A class to implement turtle graphics that will allow
one or more turtle objects to draw in a common
.
BufferedPanel
| Field Summary | |
protected boolean |
autoRepaint
Whether or not repaint occurs after each step. |
static Paint |
DEFAULT_PAINT
The default pen paint. |
private static double |
DEGREES_TO_RADIANS
Degrees to radians conversion. |
protected double |
direction
The turtle direction in degrees measured counterclockwise from the positive horizontal axis. |
private Line2D |
line
The line to draw. |
static int |
MINIMUM_SIZE
The minimum size of the common turtle buffered panel. |
(package private) GeneralPath |
path
The path to outline the turtle triangle shape. |
static int |
PEN_DOWN
Turtle pen state: pen down. |
static int |
PEN_UP
Turtle pen state: pen up. |
protected Paint |
penPaint
The turtle pen paint. |
protected int |
penState
The turtle pen state. |
private Point2D |
point1
Endpoint 1 of the line. |
private Point2D |
point2
Endpoint 2 of the line. |
static int |
PREFERRED_SIZE
The preferred size of the common turtle buffered panel. |
protected boolean |
showTurtle
Whether or not the turtle triangle is visible. |
protected static AffineTransform |
transform
The affine transform used to scale all turtle drawing. |
protected static BufferedPanel |
turtleBufferPanel
The common buffered panel for all turtle graphics. |
protected static int |
turtleBufferPanelSize
The size of the common turtle buffered panel. |
protected static Vector |
turtleList
The list of turtle objects that have been created. |
protected double |
xPosition
The turtle x position. |
protected double |
yPosition
The turtle y position. |
| Constructor Summary | |
Turtle()
The default turtle constructor creates the turtle buffered panel if that buffered panel has not been created by an earlier turtle and then adds this turtle to the list of all turtles. |
|
| Method Summary | |
static void |
clear()
Clear the common turtle buffered panel and repaint. |
protected void |
drawTurtle(Graphics2D g2)
Draw the turtle triangle at the current turtle position in the current turtle direction. |
boolean |
getAutoRepaint()
Return the current auto repaint setting. |
double |
getDirection()
Return the turtle direction. |
Paint |
getPaint()
Return the turtle pen paint. |
int |
getPenState()
Return the turtle pen state. |
Point2D |
getPosition()
Return the turtle position. |
static BufferedImage |
getTurtleBuffer()
Return the buffer in the common turtle buffered panel. |
static Graphics2D |
getTurtleBufferGraphics()
Return the graphics context for the common turtle buffered panel. |
static BufferedPanel |
getTurtleBufferPanel()
Create and return the common buffered panel for turtle graphics. |
static int |
getTurtleBufferPanelSize()
Return the size of the common buffered panel for turtle graphics. |
static Turtle[] |
getTurtles()
Return an array of all turtles that have been created. |
double |
getX()
Return the turtle x position. |
double |
getY()
Return the turtle y position. |
static void |
hideAllTurtles()
Hide all turtle triangles. |
void |
hideTurtle()
Hide the turtle triangle. |
boolean |
isVisible()
Return whether or not the turtle triangle is visible. |
static void |
repaint()
Repaint the common turtle buffered panel. |
void |
reset()
Reset the turtle to its default initial state and then repaint. |
static void |
selfTest()
A simple self test. |
void |
setAutoRepaint(boolean enabled)
Set auto repaint, that is, whether or not to repaint after each step, to the given value. |
static void |
setCoordinatesViaBounds(Rectangle2D world)
Set the coordinate system in the common turtle buffered panel using the given bounds in the world coordinate system to define the affine coordinate transformation. |
static void |
setCoordinatesViaBounds(Rectangle2D world,
int inset)
Set the coordinate system in the common turtle buffered panel using the given bounds in the world coordinate system and the given image inset to define the affine coordinate transformation. |
void |
setDirection(double direction)
Set the turtle direction in degrees counterclockwise from the positive horizontal axis. |
void |
setPaint(int r,
int g,
int b)
Set the turtle pen paint via r,g,b components. |
void |
setPaint(int r,
int g,
int b,
int alpha)
Set the turtle pen paint via r, g, b, alpha components. |
void |
setPaint(Paint paint)
Set the turtle pen paint. |
void |
setPenState(int penState)
Set the turtle pen state. |
void |
setPosition(double x,
double y)
Set the turtle position. |
void |
setPosition(Point2D position)
Set the turtle position. |
static void |
setTurtleBufferPanelSize(int size)
Set the size of the common buffered panel for turtle graphics (this must be called before the buffered panel is created). |
void |
setVisible(boolean visible)
Show or hide the turtle triangle using the given parameter to decide. |
static void |
showAllTurtles()
Show all turtle triangles. |
void |
showTurtle()
Show the turtle triangle. |
void |
step(double distance)
Move the turtle from its current position by the given distance in its current direction and if the current pen state is PEN_DOWN then draw a line using the current pen paint. |
void |
turn(double angle)
Increment the turtle direction by the given angle in degrees. |
static void |
useCenterCoordinates()
Use a coordinate system with the origin at the center of the common turtle buffered panel and with x increasing rightwards and y increasing upwards. |
static void |
useCornerCoordinates()
Use a coordinate system with the origin at the lower left corner of the common turtle buffered panel and with x increasing rightwards and y increasing upwards. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
public static final int MINIMUM_SIZE
public static final int PREFERRED_SIZE
public static final Paint DEFAULT_PAINT
public static final int PEN_UP
public static final int PEN_DOWN
private static final double DEGREES_TO_RADIANS
protected static BufferedPanel turtleBufferPanel
protected static int turtleBufferPanelSize
protected static AffineTransform transform
protected static Vector turtleList
protected double xPosition
protected double yPosition
protected double direction
protected Paint penPaint
protected int penState
protected boolean showTurtle
protected boolean autoRepaint
private Line2D line
private Point2D point1
private Point2D point2
GeneralPath path
| Constructor Detail |
public Turtle()
| Method Detail |
public static void setTurtleBufferPanelSize(int size)
size - the new turtle buffered panel sizegetTurtleBufferPanel(),
getTurtleBufferPanelSize()public static int getTurtleBufferPanelSize()
getTurtleBufferPanel(),
setTurtleBufferPanelSize(int)public static BufferedPanel getTurtleBufferPanel()
setTurtleBufferPanelSize(int),
getTurtleBufferPanelSize()public static void useCenterCoordinates()
useCornerCoordinates(),
setCoordinatesViaBounds(Rectangle2D),
setCoordinatesViaBounds(Rectangle2D, int)public static void useCornerCoordinates()
useCenterCoordinates(),
setCoordinatesViaBounds(Rectangle2D),
setCoordinatesViaBounds(Rectangle2D, int)public static void setCoordinatesViaBounds(Rectangle2D world)
world - the bounds in world coordinatesuseCenterCoordinates(),
useCornerCoordinates(),
setCoordinatesViaBounds(Rectangle2D, int)
public static void setCoordinatesViaBounds(Rectangle2D world,
int inset)
world - the bounds in world coordinatesinset - the inset of the turtle drawing within the imageuseCenterCoordinates(),
useCornerCoordinates(),
setCoordinatesViaBounds(Rectangle2D)public static Graphics2D getTurtleBufferGraphics()
public static BufferedImage getTurtleBuffer()
public static void clear()
public static void repaint()
public static Turtle[] getTurtles()
public static void showAllTurtles()
public static void hideAllTurtles()
public void step(double distance)
Move the turtle from its current position by the given distance in its current direction and if the current pen state is PEN_DOWN then draw a line using the current pen paint.
The default is to set auto repaint to true. This will give immediate feedback for each step call but will be slower if lots of step calls are made.
To improve the speed of turtle graphics at the expense of immediate feedback, make the call on a Turtle named T:
Then, to repaint the turtle buffered panel when the turtle drawing is complete, make the static call:
This design dramatically improves graphics performance.
distance - the distance to stepsetAutoRepaint(boolean),
getAutoRepaint()public void turn(double angle)
angle - the angle in degrees used to increment the directionsetDirection(double)public void showTurtle()
hideTurtle(),
setVisible(boolean),
isVisible()public void hideTurtle()
showTurtle(),
setVisible(boolean),
isVisible()public void setVisible(boolean visible)
visible - if true then show the turtle otherwise hide itshowTurtle(),
hideTurtle(),
isVisible()public boolean isVisible()
showTurtle(),
hideTurtle(),
setVisible(boolean)
public void setPosition(double x,
double y)
x - the turtle x positiony - the turtle y positionsetPosition(Point2D),
getPosition(),
getX(),
getY()public void setPosition(Point2D position)
position - the turtle positionsetPosition(double, double),
getPosition(),
getX(),
getY()public Point2D getPosition()
setPosition(double, double),
setPosition(Point2D),
getX(),
getY()public double getX()
setPosition(double, double),
setPosition(Point2D),
getPosition(),
getY()public double getY()
setPosition(double, double),
setPosition(Point2D),
getPosition(),
getX()public void setDirection(double direction)
direction - the new turtle directiongetDirection(),
turn(double)public double getDirection()
setDirection(double)public void setPaint(Paint paint)
paint - the paint to use for drawing this turtlegetPaint(),
setPaint(int, int, int),
setPaint(int, int, int, int)
public void setPaint(int r,
int g,
int b)
r - the red component of the Color to be used to paintg - the green component of the Color to be used to paintb - the blue component of the Color to be used to paintgetPaint(),
setPaint(Paint),
setPaint(int, int, int, int)
public void setPaint(int r,
int g,
int b,
int alpha)
r - the red component of the Color to be used to paintg - the green component of the Color to be used to paintb - the blue component of the Color to be used to paintalpha - the alpha component of the Color to be used to paintgetPaint(),
setPaint(Paint),
setPaint(int, int, int)public Paint getPaint()
setPaint(Paint)public void setPenState(int penState)
penState - the pen state: PEN_UP or PEN_DOWNgetPenState(),
PEN_UP,
PEN_DOWNpublic int getPenState()
setPenState(int),
PEN_UP,
PEN_DOWNpublic void setAutoRepaint(boolean enabled)
enabled - the new auto repaint settinggetAutoRepaint(),
step(double)public boolean getAutoRepaint()
setAutoRepaint(boolean),
step(double)public void reset()
protected void drawTurtle(Graphics2D g2)
Draw the turtle triangle at the current turtle position in the current turtle direction.
This method is called by the paintOver method
of the common turtle buffered panel during repaint actions.
public static void selfTest()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||