smithers.extras
Class TurtleGraphics

java.lang.Object
  extended by smithers.extras.TurtleGraphics

public class TurtleGraphics
extends java.lang.Object

Draws simple vector graphics using a 'turtle' and saves to an SVG file. The turtle has 2 unchanging parameters, angle and distance The turtle operates by reading a string of characters and performing the following actions:


Name Default character Action
Turn Left + Rotates the turtle left by angle.
Turn Right - Rotates the turtle right by angle.
Forwards F Moves the turtle forwards by distance, leaving a line behind it.
Forwards Nodraw f Moves the turtle forwards by distance.
Backwards B Moves the turtle backwards by distance, leaving a line behind it.
Backwards Nodraw b Moves the turtle backwards by distance.
Push [ Pushes the turtle's current position and direction onto the stack.
Pop ] Retrieves the turtle's current position and direction from the stack.


Constructor Summary
TurtleGraphics(double angle, double distance)
          Creates a new turtle with the specified angle and distance and the default command characters.
TurtleGraphics(double angle, double distance, char turnLeft, char turnRight, char forwards, char forwardsNodraw, char backwards, char backwardsNodraw, char push, char pop)
          Creates a new turtle according to specified options.
 
Method Summary
 void doTurtle(java.lang.String code, double x, double y, double dir, double width, double height, java.lang.String fileName)
          Draws the turtle graphics and saves an svg file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TurtleGraphics

public TurtleGraphics(double angle,
                      double distance)
Creates a new turtle with the specified angle and distance and the default command characters.

Parameters:
angle - the angle to turn by
distance - the distance to draw

TurtleGraphics

public TurtleGraphics(double angle,
                      double distance,
                      char turnLeft,
                      char turnRight,
                      char forwards,
                      char forwardsNodraw,
                      char backwards,
                      char backwardsNodraw,
                      char push,
                      char pop)
Creates a new turtle according to specified options.

Parameters:
angle - the angle to turn by (in radians)
distance - the distance to draw
turnLeft - the character to trigger turning left
turnRight - the character to trigger turning right
forwards - the character to trigger drawing forwards
forwardsNodraw - the character to trigger moving forwards
backwards - the character to trigger drawing backwards
backwardsNodraw - the character to trigger moving backwards
push - the character to store the current position
pop - the character to retrieve the last stored position
Method Detail

doTurtle

public void doTurtle(java.lang.String code,
                     double x,
                     double y,
                     double dir,
                     double width,
                     double height,
                     java.lang.String fileName)
              throws java.io.IOException
Draws the turtle graphics and saves an svg file.

Parameters:
code - the code to draw from
x - the initial x-coordinate
y - the initial y-coordinate
dir - the initial direction
width - the width of the image
height - the height of the image
fileName - the name of the file to save to
Throws:
java.io.IOException