TurtleGraphics
Class AbstractPen

java.lang.Object
  extended by TurtleGraphics.AbstractPen
All Implemented Interfaces:
Pen
Direct Known Subclasses:
BackwardPen, StandardPen

public abstract class AbstractPen
extends java.lang.Object
implements Pen

Copyright 2006 by Ken Lambert and Martin Osborne.

Provides behavior and data common to all pens.


Field Summary
protected  java.awt.Color color
           
protected  double direction
           
protected  boolean isDown
           
protected  SketchPad pad
           
protected  int width
           
protected  double xPos
           
protected  double yPos
           
 
Constructor Summary
AbstractPen(SketchPad p)
           
 
Method Summary
 void down()
          Action: The pen lowers itself to the drawing surface.
protected abstract  void drawLine(double x, double y)
           
abstract  void drawString(java.lang.String text)
          Action: Draws the string at the pen's position.
 void home()
          The pen jumps to the center of the graphics window without drawing and points north.
 boolean isDown()
           
 void move(double distance)
          Action: The pen moves the specified distance in the current direction.
 void move(double x, double y)
          Action: Moves the pen to the position (x, y).
 void setColor(java.awt.Color c)
          Action: Sets the pen's color to the specified color.
 void setDirection(double d)
          Action: The pen points in the indicated direction.
 void setWidth(int w)
          Action: Sets the pen's width to the specified width (the default width is 2 pixels).
 java.lang.String toString()
          Action: Returns information about the pen's state.
 void turn(double degrees)
          Action: The pen adds the indicated degrees to its current direction.
protected  void turn(double x, double y)
           
 void up()
          Action: The pen raises itself from the drawing surface.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

xPos

protected double xPos

yPos

protected double yPos

direction

protected double direction

width

protected int width

isDown

protected boolean isDown

color

protected java.awt.Color color

pad

protected SketchPad pad
Constructor Detail

AbstractPen

public AbstractPen(SketchPad p)
Method Detail

down

public void down()
Description copied from interface: Pen
Action: The pen lowers itself to the drawing surface.

Specified by:
down in interface Pen

drawString

public abstract void drawString(java.lang.String text)
Description copied from interface: Pen
Action: Draws the string at the pen's position.

Specified by:
drawString in interface Pen

home

public void home()
Description copied from interface: Pen
The pen jumps to the center of the graphics window without drawing and points north.

Specified by:
home in interface Pen

move

public void move(double distance)
Description copied from interface: Pen
Action: The pen moves the specified distance in the current direction. The distance can be an integer or floating-point number and is measured in pixels (picture elements). The size of a pixel depends on the monitorŐs resolution. For instance, when we say that a monitor's resolution is 800 by 600, we mean that the monitor is 800 pixels wide and 600 pixels high.

Specified by:
move in interface Pen

move

public void move(double x,
                 double y)
Description copied from interface: Pen
Action: Moves the pen to the position (x, y).

Specified by:
move in interface Pen

isDown

public boolean isDown()

setColor

public void setColor(java.awt.Color c)
Description copied from interface: Pen
Action: Sets the pen's color to the specified color.

Specified by:
setColor in interface Pen

setDirection

public void setDirection(double d)
Description copied from interface: Pen
Action: The pen points in the indicated direction. Due east corresponds to 0 degrees, north to 90 degrees, west to 180 degrees, and south to 270 degrees. Because there are 360 degrees in a circle, setting the direction to 400 would be equivalent to 400 - 360 or 40 and setting it to -30 would be equivalent to 360 - 30 or 330. Example: pen.setDirection(90); Make the pen point due north.

Specified by:
setDirection in interface Pen

setWidth

public void setWidth(int w)
Description copied from interface: Pen
Action: Sets the pen's width to the specified width (the default width is 2 pixels).

Specified by:
setWidth in interface Pen

toString

public java.lang.String toString()
Description copied from interface: Pen
Action: Returns information about the pen's state.

Specified by:
toString in interface Pen
Overrides:
toString in class java.lang.Object

turn

public void turn(double degrees)
Description copied from interface: Pen
Action: The pen adds the indicated degrees to its current direction. Positive degrees correspond to turning counterclockwise. The degrees can be an integer or floating-point number. Example: pen.turn(-45); Rotate the pen 45 degrees clockwise.

Specified by:
turn in interface Pen

up

public void up()
Description copied from interface: Pen
Action: The pen raises itself from the drawing surface.

Specified by:
up in interface Pen

drawLine

protected abstract void drawLine(double x,
                                 double y)

turn

protected void turn(double x,
                    double y)