CS 70 Turtle
Class Interface
Public interface for the CS 70 Turtle
class, which provides an interface similar to the Python Turtle
, but for generating embroidery pattern files.
Constructors & Destructors
Turtle::Turtle()
Constructor: Only a default constructor is provided.
The initial state of the turtle is
- The position is (0,0).
- The turtle is facing east.
- The pen is up.
- The color is 0.
- Satin is off.
Turtle::~Turtle()
Destructor: The destructor calls the appropriate libembroidery
cleanup.
Functions
For Setting Properties of Turtle
void Turtle::setStepSize(float step)
Sets the distance that the Turtle
will move without putting the
needle (pen) down.
When satin stitch is off, this function sets how far the needle will travel for each stitch. For example, if step size is set to 2 and the Turtle moves 10, stitches will be added at points 2, 4, 6, 8, and 10. When satin stitch is on, this function sets the width of the satin stitch.
void Turtle::satinon(float delta)
Enables satin-stitch mode. When satin stitch is on, the Turtle
will move side-to-side, creating the effect of a wider line of thread. delta
determines how far forward the Turtle
moves between each stitch, and the Turtle
’s step size determines the stitch width:
void Turtle::satinoff()
Disables satin-stitch mode. When satin stitch is off, the Turtle
will move in a straight stitch line, using the current step size.
void Turtle::pendown()
Puts the Turtle
’s pen (needle) down.
When the pen is down, the turtle will add stitches along any path it follows.
void Turtle::penup()
Raises the Turtle
’s pen.
When the pen is up, the Turtle
will “jump” from one location to another without adding any stitches.
Point Turtle::position()
Returns the Turtle
’s current position.
The position is returned as a Point
object.
For turning the Turtle
void Turtle::turntoward(const Point& pos)
Turn to face pos
.
The Turtle
’s direction is changed so that it is facing in the direction of the Point
pos
. The Turtle
’s location is not changed.
void Turtle::turntoward(const float x, const float y)
Turn to face (x,y)
.
The Turtle
’s direction is changed so that it is facing in the direction of the point (x,y)
. The Turtle
’s location is not changed.
void Turtle::setdir(const Point& pos)
Directly set the Turtle
’s direction.
The direction is set to the (normalized) value of the point pos
.
void Turtle::setdir(const float x, const float y)
Directly set the Turtle
’s direction.
The direction is set to the (normalized) value of the point (x,y)
.
void Turtle::turn(const float degreesccw)
Turns the Turle degreesccw
degrees counterclockwise.
void Turtle::right(float degreescw)
Turns the Turtle
right degreescw
degrees clockwise.
A convenience alias for turn
.
void Turtle::left(float degreesccw)
Turns the Turtle
left degreesccw
degrees counterclockwise.
A convenience alias for turn(-degreesccw)
.
Moving the Turtle
void Turtle::forward(const float dist)
Relative move forward: Moves the Turtle
dist
in the direction it is currently facing.
void Turtle::backward(const float dist)
Relative move backward: Moves the Turtle
-dist
in the direction it is currently facing.
void Turtle::move(const Point& delta)
Relative move from Turtle
’s current position
Moves the Turtle
to its current location + delta
, using the Turtle
’s current move settings.
void Turtle::move(const float x, const float y)
Relative move from Turtle
’s current position.
Moves the Turtle
to its current location plus Point(x, y)
, using the Turtle
’s current move settings.
Convenience wrapper for the version of move
that takes a Point
as its only argument.
void Turtle::gotopoint(const float x, const float y)
Absolute move: Moves the Turtle
to the point (x, y)
using the Turtle
’s current move settings.
void Turtle::gotopoint(const Point& pos)
Absolute move: Moves the Turtle
to the point (pos)
using the Turtle
’s current move settings.
For drawing text
void Turtle::displayMessage(string message, float scale)
Draws the text message
.
All letters are uppercased. Scale determines the size of the letters that are drawn. This function controls only the motion of the pen. If the pen is up, this function will go through the correct motions, but will not draw anything. To actually draw the text, you must call pendown()
beforehand.
Utility
std::ostream& operator<<(std::ostream& os, const Turtle& t)
Print a Turtle
object.
Useful for debugging.
void Turtle::end()`
Add an end marker to the embroidery file.
void Turtle::save(std::string fname)
Save to fname
.
Writes the Turtle
’s moves to an embroidery file called fname
. The extension on fname
determines the embroidery format that is used—for CS 70, we will always use the .dst
extension.
(When logged in, completion status appears here.)