public class Turtle
extends java.util.Observable
Modifier and Type | Field and Description |
---|---|
static int |
FAST |
static int |
MEDIUM |
static int |
SLOW |
Constructor and Description |
---|
Turtle()
Creates a Turtle drawing at a slow speed with a black pen of width 1.
|
Turtle(java.awt.Color c)
Creates a Turtle drawing at slow speed with a pen of specified color and width 1.
|
Turtle(int speed)
Creates a Turtle drawing at a specified speed with a black pen of width 1.
|
Turtle(int speed,
java.awt.Color c)
Creates a Turtle drawing at a specified speed with a pen of specified color and width 1.
|
Turtle(int speed,
int width)
Creates a Turtle drawing at a specified speed with a black pen of specified width.
|
Turtle(int speed,
int width,
java.awt.Color c)
Creates a Turtle drawing at a specified speed with a pen of specified width and color.
|
Modifier and Type | Method and Description |
---|---|
boolean |
backward(double pixels)
Moves turtle the specified number of pixels backwards.
|
boolean |
forward(double pixels)
Moves turtle the specified number of pixels forwards.
|
double |
getAngle()
Returns the current angle the turtle is facing.
|
java.awt.Color |
getPenColor()
Returns the current color.
|
int |
getPenWidth()
Returns the width of the pen.
|
int |
getScreenX()
Returns the current x coordinate of the turtle.
|
int |
getScreenY()
Returns the current y coordinate of the turtle.
|
int |
getSpeed()
Returns the current drawing speed
|
boolean |
isPenDown()
Returns the current pen status (down == true)
|
void |
left(double newAngle)
Changes the direction the turtle faces by newAngle radians to the left.
|
boolean |
moveTo(double x2,
double y2)
Moves the turtle to the new location using cartiasian co-ordinates.
|
void |
penDown()
Puts the pen down.
|
void |
penUp()
Lifts the pen up.
|
void |
right(double newAngle)
Changes the direction the turtle faces by newAngle radians to the right.
|
void |
setCanvas(BasicIO.GeneralCanvas gc)
Used by BasicForm.
|
void |
setJFrame(javax.swing.JFrame frame)
Used by BasicForm.
|
void |
setPenColor(java.awt.Color c)
Sets the color of the pen.
|
void |
setPenWidth(int x)
Sets the width of the pen the turtle draws with.
|
void |
setSpeed(int speed)
Sets the speed of the turtle
|
public static final int SLOW
public static final int MEDIUM
public static final int FAST
public Turtle(int speed, int width, java.awt.Color c)
speed
- the speed of the turtlewidth
- the width of the penc
- the color of the penpublic Turtle(int speed, int width)
speed
- the speed of the turtlewidth
- the width of the penpublic Turtle(int speed, java.awt.Color c)
speed
- the speed of the turtlec
- the color of the penpublic Turtle(int speed)
speed
- the speed of the turtlepublic Turtle(java.awt.Color c)
c
- the color of the penpublic Turtle()
public boolean forward(double pixels)
pixels
- number of pixels to move forwardpublic void setSpeed(int speed)
speed
- new speed of the turtlepublic boolean backward(double pixels)
pixels
- number of pixels to move backwardpublic boolean moveTo(double x2, double y2)
x2
- the new x coord of the turtley2
- the new y coord of the turtlepublic void right(double newAngle)
newAngle
- the amount to increase the angle to the rightpublic void left(double newAngle)
newAngle
- the amount to increase the angle to the leftpublic int getScreenX()
public int getScreenY()
public int getPenWidth()
public boolean isPenDown()
public int getSpeed()
public void penDown()
public void penUp()
public void setPenColor(java.awt.Color c)
c
- new Colour for the turtle's pen.public void setPenWidth(int x)
x
- new width for the penpublic double getAngle()
public java.awt.Color getPenColor()
public void setJFrame(javax.swing.JFrame frame)
frame
- the frame the turtle is drawing onpublic void setCanvas(BasicIO.GeneralCanvas gc)
gc
- the canvas the turtle is drawing on