|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.ObjectTurtle
public class Turtle
An instance is a turtle in a panel within a JFrame. The turtle is a spot on the panel, facing a certain direction and holding a colored pen. You can move the turtle from place to place, drawing as the turtle moves. You can ask the turtle to pick the pen up so that moving doesn't draw. You can draw rectangles and circles of any size around the turtle. All instances of Turtle use the same JFrame and panel.
Constructor Summary | |
---|---|
Turtle()
Constructor: a black turtle starting at the middle of the panel with angle 0 (looking east). |
|
Turtle(double x,
double y,
double ang)
Constructor: a black turtle starting at (x,y) with angle ang. |
Method Summary | |
---|---|
void |
addAngle(double ang)
Add ang degrees to the angle. |
void |
clear()
Clear the screen (make it all white). |
void |
drawCircle(double d)
Draw a circle of diameter d with center at the turtle's position. |
void |
drawRect(double w,
double h)
Draw a rectangle of width w, height h with center at the turtle's position. |
void |
fillCircle(double d)
Fill a circle of diameter d with center at the turtle's position. |
void |
fillRect(double w,
double h)
Fill a rectangle of width w, height h with center at the turtle's position. |
void |
fillTriangle(double s)
Fill triangle with lower left point at the turtle position and side length s. |
double |
getAngle()
= angle of the turtle (in degrees). |
Color |
getColor()
= the turtle's current color. |
static String |
getCommands()
= all the turtle commands carried out since the last clear(), one to a line. |
int |
getHeight()
= height of the panel. |
int |
getWidth()
= width of panel. |
double |
getX()
= x-coordinate of the turtle. |
double |
getY()
= y-coordinate of the turtle. |
boolean |
isPenUp()
= "the pen is up". |
void |
jumpTo(double x,
double y,
double ang)
Move the turtle to (x,y), without drawing, and face it at angle ang --who ever heard of turtles jumping? |
void |
moveAhead(double d)
Move the turtle d units in its current direction. |
void |
moveBack(double d)
Move the turtle d units in the opposite (backward) direction. |
void |
pause(int millisec)
Pause the program for millisec milliseconds. |
void |
putPenDown()
Put pen down. |
void |
putPenUp()
Lift pen. |
void |
setAngle(double ang)
Set the angle to ang degrees. |
void |
setColor(Color c)
Set the color of the turtle to c. |
void |
setPanelSize()
Set the panel size as big as possible in the current JFrame window. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public Turtle()
public Turtle(double x, double y, double ang)
Method Detail |
---|
public static String getCommands()
public void setPanelSize()
public double getX()
public double getY()
public double getAngle()
public int getWidth()
public int getHeight()
public boolean isPenUp()
public void setAngle(double ang)
public void addAngle(double ang)
public void putPenUp()
public void putPenDown()
public void setColor(Color c)
public Color getColor()
public void jumpTo(double x, double y, double ang)
public void drawCircle(double d)
public void fillTriangle(double s)
public void fillCircle(double d)
public void drawRect(double w, double h)
public void fillRect(double w, double h)
public void moveAhead(double d)
public void moveBack(double d)
public void clear()
public void pause(int millisec)
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |