Class Pen

java.lang.Object
  extended by Pen

public class Pen
extends java.lang.Object

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.)

Version:
2015.06.08
Author:
Michael Kölling & David J. Barnes (Changed bij Sjaak Smetsers)

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

Pen

public Pen(int xPos,
           int yPos,
           int rotation,
           Canvas drawingCanvas)
Create a new Pen for a given canvas. The initial color is black, and the pen is down. The position of the pen is given w.r.t. the origin located in the lower left corner of the window.

Parameters:
xPos - the initial horizontal coordinate of the pen
yPos - the initial vertical coordinate of the pen
rotation - the initial rotation of the pen
drawingCanvas - the canvas to draw on
Method Detail

move

public void move(int distance)
Move the specified distance in the current direction. If the pen is down, leave a line on the canvas.

Parameters:
distance - The distance to move forward from the current location.

moveTo

public void moveTo(int x,
                   int y)
Move to the specified location. If the pen is down, leave a line on the canvas.

Parameters:
x - The x-coordinate to move to.
y - The y-coordinate to move to.

penDown

public void penDown()
Put the pen down. Moving afterwards will leave a line on the canvas.


penUp

public void penUp()
Lift the pen up. Moving afterwards will not leave a line on the canvas.


restore

public void restore()

save

public void save()

setColor

public void setColor(java.awt.Color newColor)
Set the drawing color.

Parameters:
newColor - The color to use for subsequent drawing operations.

turn

public void turn(int degrees)
Turn the specified amount (out of a 360 degree circle) clockwise from the current rotation.

Parameters:
degrees - The amount of degrees to turn. (360 is a full circle.)

turnTo

public void turnTo(int angle)
Turn to the specified direction. 0 is right, 90 is down, 180 is left, 270 is up.

Parameters:
angle - The angle to turn to.