diff --git a/demo/Makefile b/demo/Makefile index 4b03478..db87a2a 100644 --- a/demo/Makefile +++ b/demo/Makefile @@ -1,4 +1,4 @@ -all: demo +all: demo cross-stitch-demo demo: demo.o clang++ demo.o ../src/libturtle.a ../src/libpoint.a ../libembroidery/libembroidery.a -o demo @@ -6,5 +6,11 @@ demo: demo.o 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 diff --git a/doc/cross-stitch-demo.md b/doc/cross-stitch-demo.md new file mode 100644 index 0000000..b28248d --- /dev/null +++ b/doc/cross-stitch-demo.md @@ -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. \ No newline at end of file diff --git a/src/turtle.cpp b/src/turtle.cpp index 19f87d2..5eeaaf0 100644 --- a/src/turtle.cpp +++ b/src/turtle.cpp @@ -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>& coordinates) { + + for (std::pair& 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 diff --git a/src/turtle.hpp b/src/turtle.hpp index 5276152..ab9a0a6 100644 --- a/src/turtle.hpp +++ b/src/turtle.hpp @@ -35,6 +35,8 @@ class Turtle { void displayMessage(std::string message, float scale); + void createCrossStitchPattern(std::vector>& coordinates); + void save(std::string fname); void end(); @@ -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);