java.lang.ObjectPen
public class Pen
A pen can be used to draw on a canvas. The pen maintains a position, direction, color, and an up/down state. The pen can be moved across the canvas. If the pen is down, it leaves a line on the canvas when moved. (If it is up, it will not draw a line.)
| Constructor Summary | |
|---|---|
Pen(int xPos,
int yPos,
int rotation,
Canvas drawingCanvas)
Create a new Pen for a given canvas. |
|
| Method Summary | |
|---|---|
void |
move(int distance)
Move the specified distance in the current direction. |
void |
moveTo(int x,
int y)
Move to the specified location. |
void |
penDown()
Put the pen down. |
void |
penUp()
Lift the pen up. |
void |
restore()
|
void |
save()
|
void |
setColor(java.awt.Color newColor)
Set the drawing color. |
void |
turn(int degrees)
Turn the specified amount (out of a 360 degree circle) clockwise from the current rotation. |
void |
turnTo(int angle)
Turn to the specified direction. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public Pen(int xPos,
int yPos,
int rotation,
Canvas drawingCanvas)
xPos - the initial horizontal coordinate of the penyPos - the initial vertical coordinate of the penrotation - the initial rotation of the pendrawingCanvas - the canvas to draw on| Method Detail |
|---|
public void move(int distance)
distance - The distance to move forward from the current location.
public void moveTo(int x,
int y)
x - The x-coordinate to move to.y - The y-coordinate to move to.public void penDown()
public void penUp()
public void restore()
public void save()
public void setColor(java.awt.Color newColor)
newColor - The color to use for subsequent drawing operations.public void turn(int degrees)
degrees - The amount of degrees to turn. (360 is a full circle.)public void turnTo(int angle)
angle - The angle to turn to.