uwcse.graphics
Class Pen

java.lang.Object
  |
  +--uwcse.graphics.Pen

public class Pen
extends java.lang.Object

A simple Pen class which implements turtle style graphics. The pen has a position and an angle, and can be either up or down. All distances are in pixels. Angles are specified in degrees. Each pen automatically creates its own window.


Constructor Summary
Pen()
          Create a new Pen and a new window for the pen.
 
Method Summary
 void down()
          Set the pen's state to down.
 void erase()
          Erase the window.
 void home()
          Send the pen to the home position and angle.
static void main(java.lang.String[] args)
          Test the pen with the squiral method.
 void move(int distance)
          Move the pen the given distance.
 void squiral(int steps, int angle, int distance)
          Draw a squiral.
 java.lang.String toString()
          Return the pen's printed representation.
 void turn(int degrees)
          Turn the pen this many degrees counter-clockwise.
 void up()
          Raise the pen.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Pen

public Pen()
Create a new Pen and a new window for the pen. By default, the pen is created in the down state, and positioned in the center of the window, facing right (angle 0).
Method Detail

down

public void down()
Set the pen's state to down.

erase

public void erase()
Erase the window.

home

public void home()
Send the pen to the home position and angle.

main

public static void main(java.lang.String[] args)
Test the pen with the squiral method.

move

public void move(int distance)
Move the pen the given distance. If the pen is down, a line is drawn.

squiral

public void squiral(int steps,
                    int angle,
                    int distance)
Draw a squiral.
Parameters:
steps - the number of steps (lines) to draw
angle - the amount to turn after each step
distance - the length by which to grow every third line

toString

public java.lang.String toString()
Return the pen's printed representation.
Overrides:
toString in class java.lang.Object

turn

public void turn(int degrees)
Turn the pen this many degrees counter-clockwise.
Parameters:
degrees - a positive number is degrees to the "left"

up

public void up()
Raise the pen.