Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion demo/Makefile
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
all: demo
all: demo cross-stitch-demo

demo: demo.o
clang++ demo.o ../src/libturtle.a ../src/libpoint.a ../libembroidery/libembroidery.a -o demo

demo.o: demo.cpp
clang++ -g -c -std=c++1z -Wall -Wextra -pedantic -I../libembroidery demo.cpp

cross-stitch-demo: cross-stitch-demo.o
clang++ cross-stitch-demo.o ../src/libturtle.a ../src/libpoint.a ../libembroidery/libembroidery.a -o cross-stitch-demo

cross-stitch-demo.o: cross-stitch-demo.cpp
clang++ -g -c -std=c++1z -Wall -Wextra -pedantic -I../libembroidery cross-stitch-demo.cpp

clean:
rm *.o demo
10 changes: 10 additions & 0 deletions doc/cross-stitch-demo.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Cross stitching demo
This demo takes you through how to use the Turtle's cross stitching function. Cross stitching is the process of making an image out of many small x shaped stitches. Example: https://www.needlework-tips-and-techniques.com/images/homemade-valentines-cards.jpg
## Step 1. Find a pattern you like
Go on line and find a cross stitch pattern you like, or create your own on graph paper! You should have a couple colors in mind, and know at what coordinate you would like each of those colors to be filled in.
## Step 2. Convert this to a vector of coordinates
Make a different vector of coordinates for each color that you have, placing them in the same C file. It should be a vector of pairs, as shown in the cross-stitch-demo.cpp file in the demo folder.
## Step 3. Add alignment-helper coordinates
Add the pair {0,0} to each of your vectors. The reason we do this is so, when we embroider each layer, we can align them against your embroidery piece at the {0,0} point. Otherwise, it is impossible to tell at what part on the fabric we should be embroidering the next layer. (You can also use an arbitrarily large point, like {20,20}).
## Step 4. Embroidery!
Pass your vector into the Turtle's provided function as shown in cross-stitch-demo.cpp. Compile and run, and your file should be generated! Do this as many times as you need, and upload your DST files onto the machine and embroider them separately.
38 changes: 38 additions & 0 deletions src/turtle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,44 @@ void Turtle::check_density(const Point& pos) {
density_error_ |= (entry->second > DENSITY_ERROR_LIMIT);
}

// draws an X of fixed size at (x,y)
void Turtle::drawX(int x, int y) {
right(45);
gotopoint(x,y);

pendown();
forward(10);
penup();
left(45);
left(45);

gotopoint(x+9,y);
pendown();
backward(10);
penup();
right(45);
}

// given a list of coordinates on a 1x1 grid, stitch the cross stitches of fixed size
void Turtle::createCrossStitchPattern(std::vector<std::pair<int, int>>& coordinates) {

for (std::pair<int, int>& coord : coordinates) {
coord.first *= 6;
coord.second *= 6;
}

// draw a random stitch as a reference point
gotopoint(0,0);
pendown();
forward(5);
penup();

for (const auto& coord : coordinates) {
drawX(coord.first, coord.second); // Draw the X at each coordinate
}

}

/* Disabled functions -- we could use these at some point, but they feel too
high-level for providing to CS70

Expand Down
3 changes: 3 additions & 0 deletions src/turtle.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ class Turtle {

void displayMessage(std::string message, float scale);

void createCrossStitchPattern(std::vector<std::pair<int, int>>& coordinates);

void save(std::string fname);
void end();

Expand All @@ -51,6 +53,7 @@ class Turtle {
void set_y(const float y);
void increment_x(const float x);
void increment_y(const float y);
void drawX(int x, int y);
// void rectangle(float w, float h);
// void circle(float radius);
// void snowflake(float sidelength, int levels);
Expand Down