From 70caf332151db9a22f3fb9339ce3443b9741daa4 Mon Sep 17 00:00:00 2001 From: kittyk4t21 Date: Wed, 25 Oct 2023 16:15:28 -0700 Subject: [PATCH 1/6] decorative_stitches use decorative stitches to create interesting lines, lets you just move forward but create a different shape --- .DS_Store | Bin 0 -> 8196 bytes .vscode/c_cpp_properties.json | 18 ++ .vscode/launch.json | 13 ++ .vscode/settings.json | 59 ++++++ demo/demo.cpp | 37 +++- src/turtle.cpp | 383 +++++++++++++++++++++++++++++----- src/turtle.hpp | 132 ++++++------ 7 files changed, 524 insertions(+), 118 deletions(-) create mode 100644 .DS_Store create mode 100644 .vscode/c_cpp_properties.json create mode 100644 .vscode/launch.json create mode 100644 .vscode/settings.json diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..7696ea2640a74777ad39303de13146d9373bf916 GIT binary patch literal 8196 zcmeHMPfrs;6n_I%wji?nDMHkwu@@5v)JP&Ed1;f5z|xIKFdkAi%bPYcv8}gxD}!P{F`yVw3@8Q^1LuJOd}njf zPI&LjUR5gw6a)Vy1N?r7V&Rwwur5(t9axDJ05ODSA*hQ_f5a#^ASME=OGFC_k)en( zlmsaT2{H#F!?8aR_}3-Ma3Er494DBW1Q`km5)Tp;?m!X}Rjn9M474-AbN3JwfI=Bq zOa4BGeG|Wgh`^?wS@SAEp8wIT*p}zV<6lTeXXwJkF0D)J(Y7+%td{W&zv?9ocZ0W9 z8MDoXZkTHpt>yHgdFJ?r@c#bfcyw|) zelQ;0pP7k|N2eyI4-UdwBzEi0N^Zw4JM4vACUaR8?I|OC7RsZvJI2k%TAK{J}YxiJ{m40 z?NUCHm^)K3@|IJI&Hj)y#uDjUa-LeQygv+TwvJZN8N?JmZSb2y^kLCQzHL~!+*;9S~%3;AsDcOtQCCz+YwHH+O_cN&o-= literal 0 HcmV?d00001 diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json new file mode 100644 index 0000000..97c1779 --- /dev/null +++ b/.vscode/c_cpp_properties.json @@ -0,0 +1,18 @@ +{ + "configurations": [ + { + "name": "macos-clang-x64", + "includePath": [ + "${workspaceFolder}/**" + ], + "compilerPath": "/usr/bin/clang", + "cStandard": "${default}", + "cppStandard": "${default}", + "intelliSenseMode": "macos-clang-x64", + "compilerArgs": [ + "" + ] + } + ], + "version": 4 +} \ No newline at end of file diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..bb9442e --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,13 @@ +{ + "version": "0.2.0", + "configurations": [ + { + "name": "C/C++ Runner: Debug Session", + "type": "lldb", + "request": "launch", + "args": [], + "cwd": "/Users/katianawieser/libturtle/demo", + "program": "/Users/katianawieser/libturtle/demo/build/Debug/outDebug" + } + ] +} \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..b9c6ac8 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,59 @@ +{ + "C_Cpp_Runner.cCompilerPath": "clang", + "C_Cpp_Runner.cppCompilerPath": "clang++", + "C_Cpp_Runner.debuggerPath": "lldb", + "C_Cpp_Runner.cStandard": "", + "C_Cpp_Runner.cppStandard": "", + "C_Cpp_Runner.msvcBatchPath": "", + "C_Cpp_Runner.useMsvc": false, + "C_Cpp_Runner.warnings": [ + "-Wall", + "-Wextra", + "-Wpedantic", + "-Wshadow", + "-Wformat=2", + "-Wcast-align", + "-Wconversion", + "-Wsign-conversion", + "-Wnull-dereference" + ], + "C_Cpp_Runner.msvcWarnings": [ + "/W4", + "/permissive-", + "/w14242", + "/w14287", + "/w14296", + "/w14311", + "/w14826", + "/w44062", + "/w44242", + "/w14905", + "/w14906", + "/w14263", + "/w44265", + "/w14928" + ], + "C_Cpp_Runner.enableWarnings": true, + "C_Cpp_Runner.warningsAsError": false, + "C_Cpp_Runner.compilerArgs": [], + "C_Cpp_Runner.linkerArgs": [], + "C_Cpp_Runner.includePaths": [], + "C_Cpp_Runner.includeSearch": [ + "*", + "**/*" + ], + "C_Cpp_Runner.excludeSearch": [ + "**/build", + "**/build/**", + "**/.*", + "**/.*/**", + "**/.vscode", + "**/.vscode/**" + ], + "C_Cpp_Runner.useAddressSanitizer": false, + "C_Cpp_Runner.useUndefinedSanitizer": false, + "C_Cpp_Runner.useLeakSanitizer": false, + "C_Cpp_Runner.showCompilationTime": false, + "C_Cpp_Runner.useLinkTimeOptimization": false, + "C_Cpp_Runner.msvcSecureNoWarnings": false +} \ No newline at end of file diff --git a/demo/demo.cpp b/demo/demo.cpp index eca9fc1..58ad534 100644 --- a/demo/demo.cpp +++ b/demo/demo.cpp @@ -7,27 +7,50 @@ using namespace std; -void rect(Turtle& t, float width, float height) { +void rect(Turtle &t, float width, float height) +{ t.forward(width); t.right(90); + t.set_decor_stitch(3); t.forward(height); t.right(90); + t.set_decor_stitch(1); t.forward(width); t.right(90); + t.set_decor_stitch(2); t.forward(height); t.right(90); } +void penta(Turtle &t, float width) +{ + t.decor_on(0); + for (int i = 0; i < 5; i++) + { + t.set_decor_stitch(i); + t.forward(width); + t.left(72); + } +} -void meetTurtle() { +void meetTurtle() +{ Turtle t; - t.satinon(0.3); - t.pendown(); - rect(t, 20, 30); + // t.satinon(0.3); + // t.decor_on(0); + t.pendown(); + t.decor_on(5); + // t.forward(20); + // t.decor_on(4); + // rect(t, 30, 30); + t.setStepSize(10); + // penta(t, 50); + t.forward(60); t.end(); t.save("demo.dst"); } -int main() { - meetTurtle(); +int main() +{ + meetTurtle(); } diff --git a/src/turtle.cpp b/src/turtle.cpp index 19f87d2..51c650c 100644 --- a/src/turtle.cpp +++ b/src/turtle.cpp @@ -20,17 +20,21 @@ Turtle::Turtle() pen_is_down_{false}, satin_is_on_{false}, satin_delta_{.5}, + decor_stitch_{0}, + decor_active_{false}, dir_{Point(1, 0)}, position_{Point(0, 0)}, density_error_{false}, - density_warning_{false} { + density_warning_{false} +{ embPattern_addThread( emb_, EmbThread{embColor_make(0, 0, 0), "Default color", "0"}); embPattern_changeColor(emb_, 1); } /** Destructor: The destructor calls the appropriate libembroidery cleanup. */ -Turtle::~Turtle() { +Turtle::~Turtle() +{ embPattern_free(emb_); } @@ -42,7 +46,8 @@ Turtle::~Turtle() { will be added at 2, 4, 6, 8, and 10. * When satin sttich is on, this sets the *width* of the satin stitch. */ -void Turtle::setStepSize(float step) { +void Turtle::setStepSize(float step) +{ stepsize_ = step; } @@ -50,24 +55,67 @@ void Turtle::setStepSize(float step) { * When satin stitch is on, the Turtle will move side to side, * creating the effect of a wider line of thread. */ -void Turtle::satinon(float delta) { +void Turtle::satinon(float delta) +{ satin_is_on_ = true; satin_delta_ = delta; + decor_off(); } /** 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::satinoff() { +void Turtle::satinoff() +{ satin_is_on_ = false; } +/* +Sets the decorative stitch to be drawn with the turtle, does NOT turn it on though +Stitch Key + * 0: Arrow stitch + * 1: ZigZag stitch + * 2: Feather stitch + * 3: Blanket stitch + * 4: Leaf & Vine Stitch +*/ +void Turtle::set_decor_stitch(int index) +{ + decor_stitch_ = index; +} + +/** + * Enables decorative stitches; sets stitch to stitch # passed in + * Stitch Key + * 0: Arrow stitch + * 1: ZigZag stitch + * 2: Feather stitch + * 3: Blanket stitch + * 4: Leaf & Vine Stitch + * + */ +void Turtle::decor_on(int index) +{ + decor_active_ = true; + decor_stitch_ = index; +} + +/** + * Disables all decorative stitches + * + */ +void Turtle::decor_off() +{ + decor_active_ = false; +} + /** Puts the turtle's pen down. * When the pen is down, the turtle will add stitches along any * path it follows. */ -void Turtle::pendown() { +void Turtle::pendown() +{ pen_is_down_ = true; } @@ -75,14 +123,16 @@ void Turtle::pendown() { * When the pen is up, the turtle will "jump" from one location * to another without adding any stitches. */ -void Turtle::penup() { +void Turtle::penup() +{ pen_is_down_ = false; } /** Returns the Turtle's current position. * The position is returned as a Point object. */ -Point Turtle::position() { +Point Turtle::position() +{ return position_; } @@ -92,7 +142,8 @@ Point Turtle::position() { * 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 Point& pos) { +void Turtle::turntoward(const Point &pos) +{ Point delta = pos - position_; dir_ = delta.normalize(1); } @@ -102,7 +153,8 @@ void Turtle::turntoward(const Point& pos) { * the point `(x,y)`. The turtle's location is not changed. */ -void Turtle::turntoward(const float x, const float y) { +void Turtle::turntoward(const float x, const float y) +{ turntoward(Point(x, y)); } @@ -110,7 +162,8 @@ void Turtle::turntoward(const float x, const float y) { * The direction is set to the (normalized) value of * the point `pos`. */ -void Turtle::setdir(const Point& pos) { +void Turtle::setdir(const Point &pos) +{ dir_ = pos.normalize(1); } @@ -118,12 +171,14 @@ void Turtle::setdir(const Point& pos) { * The direction is set to the (normalized) value of * the point `(x,y)`. */ -void Turtle::setdir(const float x, const float y) { +void Turtle::setdir(const float x, const float y) +{ setdir(Point(x, y)); } /** Turns the Turle `degreesccw` degrees. */ -void Turtle::turn(const float degreesccw) { +void Turtle::turn(const float degreesccw) +{ float radcw = -degreesccw / 180.0 * 3.141592653589; dir_ = Point(cos(radcw) * dir_.x_ - sin(radcw) * dir_.y_, sin(radcw) * dir_.x_ + cos(radcw) * dir_.y_); @@ -132,14 +187,16 @@ void Turtle::turn(const float degreesccw) { /** Turns the turtle right `degreesccw`. * This is a convenience alias for `turn`. */ -void Turtle::right(float degreesccw) { +void Turtle::right(float degreesccw) +{ turn(degreesccw); } /** Turns the turtle left `degreesccw`. * This is a convenience alias for `turn(-degreesccw)`. */ -void Turtle::left(float degreesccw) { +void Turtle::left(float degreesccw) +{ turn(-degreesccw); } @@ -149,7 +206,8 @@ void Turtle::left(float degreesccw) { * Moves the Turtle to its current location + `delta`, * using the Turtle's current move settings. */ -void Turtle::move(const Point& delta) { +void Turtle::move(const Point &delta) +{ gotopoint(position_ + delta); } @@ -160,7 +218,8 @@ void Turtle::move(const Point& delta) { * only argument. */ -void Turtle::move(const float x, const float y) { +void Turtle::move(const float x, const float y) +{ move(Point(x, y)); } @@ -168,7 +227,8 @@ void Turtle::move(const float x, const float y) { * Moves the Turtle to the point `(x, y)` using the Turtle's * current move settings. */ -void Turtle::gotopoint(const float x, const float y) { +void Turtle::gotopoint(const float x, const float y) +{ gotopoint(Point(x, y)); } @@ -176,17 +236,51 @@ void Turtle::gotopoint(const float x, const float y) { * Moves the Turtle to the point `(pos)` using the Turtle's * current move settings. */ -void Turtle::gotopoint(const Point& pos) { +void Turtle::gotopoint(const Point &pos) +{ // if (pos == position_) { // return; //} - if (pen_is_down_) { - if (satin_is_on_) { + if (pen_is_down_) + { + if (satin_is_on_) + { satin_stitch_to(pos); - } else { - stitch_to(pos); } - } else { + else + { + if (decor_active_) + { + switch (decor_stitch_) + { + case 0: + arrow_stitch_to(pos); + break; + case 1: + zigzag_stitch_to(pos); + break; + case 2: + feather_stitch_to(pos); + break; + case 3: + blanket_stitch_to(pos); + break; + case 4: + leafVine_stitch_to(pos); + break; + case 5: + squareZag_stitch_to(pos); + break; + } + } + else + { + stitch_to(pos); + } + } + } + else + { jump_to(pos); } } @@ -195,7 +289,8 @@ void Turtle::gotopoint(const Point& pos) { * Moves the turtle `dist` in the direction it * is currently facing. */ -void Turtle::forward(const float dist) { +void Turtle::forward(const float dist) +{ move(dir_ * dist); } @@ -203,7 +298,8 @@ void Turtle::forward(const float dist) { * Moves the turtle `-dist` in the direction it * is currently facing. */ -void Turtle::backward(const float dist) { +void Turtle::backward(const float dist) +{ move(dir_ * dist * -1); } @@ -216,11 +312,13 @@ void Turtle::backward(const float dist) { * Scale determines the size of the letters that are drawn. */ -bool notInAlphabet(char c) { +bool notInAlphabet(char c) +{ return Alphabet.find(c) == Alphabet.end(); } -void Turtle::displayMessage(string message, float scale) { +void Turtle::displayMessage(string message, float scale) +{ transform(message.begin(), message.end(), message.begin(), ::toupper); message.erase(remove_if(message.begin(), message.end(), notInAlphabet), message.end()); @@ -229,15 +327,17 @@ void Turtle::displayMessage(string message, float scale) { float start_y = position_.y_; float max_x = position_.x_; - for (char& nextChar : message) { + for (char &nextChar : message) + { penup(); - for (const Point& p : Alphabet[nextChar]) { + for (const Point &p : Alphabet[nextChar]) + { move(p * scale); if (position_.x_ > max_x) max_x = position_.x_; pen_is_down_ = pen_was_down; } - penup(); // raise pen to jump to next letter + penup(); // raise pen to jump to next letter gotopoint(max_x + 3 * scale, start_y); pen_is_down_ = pen_was_down; } @@ -248,7 +348,8 @@ void Turtle::displayMessage(string message, float scale) { /** Print a Turtle object. * Useful for debugging. */ -std::ostream& operator<<(std::ostream& os, const Turtle& t) { +std::ostream &operator<<(std::ostream &os, const Turtle &t) +{ os << "Turtle(position=" << t.position_ << ",Direction=" << t.dir_ << ")"; return os; } @@ -257,7 +358,8 @@ std::ostream& operator<<(std::ostream& os, const Turtle& t) { * This is very important -- without it, the embroidery machine * doesn't read the file correctly. */ -void Turtle::end() { +void Turtle::end() +{ embPattern_addStitchRel(emb_, 0, 0, END, color_); } @@ -266,12 +368,16 @@ void Turtle::end() { * The extension on `fname` determines the embroidery format that is used. * For CS70, we will always use the `.dst` extension. */ -void Turtle::save(std::string fname) { - if (density_error_) { +void Turtle::save(std::string fname) +{ + if (density_error_) + { cerr << "Not writing output file because density errors occurred:" << endl; - for (const auto& entry : density_) { - if (entry.second > DENSITY_ERROR_LIMIT) { + for (const auto &entry : density_) + { + if (entry.second > DENSITY_ERROR_LIMIT) + { cerr << " " << entry.second << " stitches at " << entry.first << endl; } @@ -279,11 +385,14 @@ void Turtle::save(std::string fname) { return; } - if (density_warning_) { + if (density_warning_) + { cerr << "Use caution with output file; density warnings occurred:" << endl; - for (const auto& entry : density_) { - if (entry.second > DENSITY_WARN_LIMIT) { + for (const auto &entry : density_) + { + if (entry.second > DENSITY_WARN_LIMIT) + { cerr << " * " << entry.second << " stitches at " << entry.first << endl; } @@ -294,50 +403,218 @@ void Turtle::save(std::string fname) { // Lower-level functions, set to private -void Turtle::stitch(const Point& pos) { +void Turtle::stitch(const Point &pos) +{ embPattern_addStitchRel(emb_, pos.x_, pos.y_, 0, color_); check_density(position_ + pos); position_ += pos; } -void Turtle::stitch_abs(const Point& pos) { +void Turtle::stitch_abs(const Point &pos) +{ embPattern_addStitchAbs(emb_, pos.x_, pos.y_, 0, color_); check_density(pos); position_ = pos; } -void Turtle::jump_to(const Point& pos) { +void Turtle::jump_to(const Point &pos) +{ embPattern_addStitchAbs(emb_, pos.x_, pos.y_, JUMP, color_); // check_density(pos); position_ = pos; } -void Turtle::stitch_to(const Point& pos) { +void Turtle::stitch_to(const Point &pos) +{ float total_length = (position_ - pos).length(); size_t num_stitches = abs(int(total_length / stepsize_)); Point step = (pos - position_) / num_stitches; - for (size_t i = 0; i < num_stitches; ++i) { + for (size_t i = 0; i < num_stitches; ++i) + { stitch(step); } stitch_abs(pos); } +void Turtle::arrow_stitch_to(const Point &pos) +{ + float total_length = (position_ - pos).length(); + size_t num_stitches = abs(int(total_length / stepsize_)); + + // Point step = (pos - position_) / num_stitches; + // Point end = position_; + for (size_t i = 0; i < num_stitches; ++i) + { + + stitch(dir_ * stepsize_); // first stitch, straight line + // right diagonal + right(45); // turn right + stitch(dir_ * stepsize_ / 2); // stitch forward, half a step in the turned direction + stitch(dir_ * -1 * stepsize_ / 2); // stitch backward + left(45); // reset orientation forward + + // left diagonal + left(45); // turn left + stitch(dir_ * stepsize_ / 2); // stitch forward, half a step in the turned direction + stitch(dir_ * -1 * stepsize_ / 2); // backward + right(45); // reset orientation forward + } + stitch_abs(pos); +} -void Turtle::satin_stitch_to(const Point& pos) { +void Turtle::zigzag_stitch_to(const Point &pos) +{ + float total_length = (position_ - pos).length(); + size_t num_stitches = abs(int(total_length / stepsize_ / sqrt(2))); + + // Point step = (pos - position_) / num_stitches; + // Point end = position_; + + right(45); + for (size_t i = 0; i < num_stitches; ++i) + { + stitch(dir_ * stepsize_); // first stitch, straight line + left(90); + stitch(dir_ * stepsize_); + right(90); + } + left(45); + stitch_abs(pos); +} + +void Turtle::feather_stitch_to(const Point &pos) +{ + float total_length = (position_ - pos).length(); + size_t num_stitches = abs(int(total_length / stepsize_ / .35)) - 1; + bool go_left = true; + + right(45); + stitch(dir_ * stepsize_ / 2); // first stitch, straight line + for (size_t i = 0; i < num_stitches; ++i) + { + stitch(dir_ * stepsize_ / 2 * -1); // first stitch, straight line + + if (go_left) + { + left(90); + } + else + { + right(90); + } + stitch(dir_ * stepsize_); + go_left = !go_left; + } + stitch(dir_ * stepsize_ * -1); + + if (go_left) + { + left(45); + } + else + { + right(45); + } + + stitch_abs(pos); +} + +void Turtle::blanket_stitch_to(const Point &pos) +{ + float total_length = (position_ - pos).length(); + size_t num_stitches = abs(int(total_length / stepsize_)); + + // Point step = (pos - position_) / num_stitches; + // Point end = position_; + for (size_t i = 0; i < num_stitches; ++i) + { + stitch(dir_ * stepsize_); // first stitch, straight line + // right diagonal + right(90); // turn right + stitch(dir_ * stepsize_ / 2); // stitch forward, half a step in the turned direction + stitch(dir_ * -1 * stepsize_ / 2); // stitch backward + left(90); + } + stitch_abs(pos); +} + +void Turtle::leafVine_stitch_to(const Point &pos) +{ + float total_length = (position_ - pos).length(); + size_t num_stitches = abs(int(total_length / stepsize_)); + bool go_left = true; + + for (size_t i = 0; i < num_stitches; ++i) + { + stitch(dir_ * stepsize_); // first stitch, straight line + if (go_left) + { + // right diagonal + left(45); // turn right + stitch(dir_ * stepsize_ / 2); // stitch forward, half a step in the turned direction + right(45); + stitch(dir_ * stepsize_ / 2); + right(135); + stitch(dir_ * stepsize_ / 2); + right(45); + stitch(dir_ * stepsize_ / 2); + left(180); + } + else + { + // right diagonal + right(45); // turn right + stitch(dir_ * stepsize_ / 2); // stitch forward, half a step in the turned direction + left(45); + stitch(dir_ * stepsize_ / 2); + left(135); + stitch(dir_ * stepsize_ / 2); + left(45); + stitch(dir_ * stepsize_ / 2); + right(180); + } + go_left = !go_left; + } + stitch_abs(pos); +} + +void Turtle::squareZag_stitch_to(const Point &pos) +{ + float total_length = (position_ - pos).length(); + size_t num_stitches = abs(int(total_length / stepsize_)); + + for (size_t i = 0; i < num_stitches; ++i) + { + stitch(dir_ * stepsize_ / 2); + left(90); + stitch(dir_ * stepsize_ / 2); + right(90); + stitch(dir_ * stepsize_ / 2); + right(90); + stitch(dir_ * stepsize_ / 2); + left(90); + } + stitch_abs(pos); +} + +void Turtle::satin_stitch_to(const Point &pos) +{ float total_length = (position_ - pos).length(); size_t num_stitches = abs(int(total_length / satin_delta_)); Point step = (pos - position_) / num_stitches; Point old_dir = dir_; - if (num_stitches > 0) { + if (num_stitches > 0) + { turntoward(pos); left(90); stitch(dir_ * -stepsize_ / 2); } - for (size_t i = 0; i < num_stitches; ++i) { + for (size_t i = 0; i < num_stitches; ++i) + { stitch(dir_ * stepsize_); stitch(step + dir_ * -stepsize_); } @@ -346,14 +623,18 @@ void Turtle::satin_stitch_to(const Point& pos) { dir_ = old_dir; } -void Turtle::check_density(const Point& pos) { +void Turtle::check_density(const Point &pos) +{ string key = pos.tostr(DENSITY_PRECISION); auto entry = density_.find(key); - if (entry == density_.end()) { + if (entry == density_.end()) + { density_[key] = 1; entry = density_.find(key); - } else { + } + else + { entry->second++; } density_warning_ |= (entry->second > DENSITY_WARN_LIMIT); diff --git a/src/turtle.hpp b/src/turtle.hpp index 5276152..9f8b8ce 100644 --- a/src/turtle.hpp +++ b/src/turtle.hpp @@ -6,73 +6,85 @@ #include "point.hpp" #include -class Turtle { - public: - Turtle(); - ~Turtle(); +class Turtle +{ +public: + Turtle(); + ~Turtle(); - void setStepSize(float step); - void satinon(float delta); - void satinoff(); - void pendown(); - void penup(); - Point position(); + void setStepSize(float step); + void satinon(float delta); + void satinoff(); + void set_decor_stitch(int index); + void decor_on(int index); + void decor_off(); + void pendown(); + void penup(); + Point position(); - void turntoward(const Point& pos); - void turntoward(const float x, const float y); - void setdir(const Point& pos); - void setdir(const float x, const float y); - void turn(const float degreesccw); - void right(float degreesccw); - void left(float degreesccw); + void turntoward(const Point &pos); + void turntoward(const float x, const float y); + void setdir(const Point &pos); + void setdir(const float x, const float y); + void turn(const float degreesccw); + void right(float degreesccw); + void left(float degreesccw); - void move(const Point& delta); - void move(const float x, const float y); - void gotopoint(const Point& pos); - void gotopoint(const float x, const float y); - void forward(const float dist); - void backward(const float dist); + void move(const Point &delta); + void move(const float x, const float y); + void gotopoint(const Point &pos); + void gotopoint(const float x, const float y); + void forward(const float dist); + void backward(const float dist); - void displayMessage(std::string message, float scale); + void displayMessage(std::string message, float scale); - void save(std::string fname); - void end(); + void save(std::string fname); + void end(); - friend std::ostream& operator<<(std::ostream& os, const Turtle& t); + friend std::ostream &operator<<(std::ostream &os, const Turtle &t); - private: - void stitch(const Point& pos); - void stitch_abs(const Point& pos); - void jump_to(const Point& pos); - void stitch_to(const Point& pos); - void satin_stitch_to(const Point& pos); - void check_density(const Point& pos); - void set_x(const float x); - void set_y(const float y); - void increment_x(const float x); - void increment_y(const float y); - // void rectangle(float w, float h); - // void circle(float radius); - // void snowflake(float sidelength, int levels); - // void flakeside(float sidelength, int levels); - // void squareSpiral(int line); - // void tree(int branch); - // void svtree(float trunklength, int levels, float trunkwidth); - private: - static const int DENSITY_PRECISION = 0; - static const int DENSITY_WARN_LIMIT = 15; - static const int DENSITY_ERROR_LIMIT = 20; - EmbPattern* emb_; - float stepsize_; - int color_; - bool pen_is_down_; - bool satin_is_on_; - float satin_delta_; - Point dir_; - Point position_; - std::map density_; - bool density_error_; - bool density_warning_; +private: + void stitch(const Point &pos); + void stitch_abs(const Point &pos); + void jump_to(const Point &pos); + void stitch_to(const Point &pos); + void arrow_stitch_to(const Point &pos); + void zigzag_stitch_to(const Point &pos); + void feather_stitch_to(const Point &pos); + void blanket_stitch_to(const Point &pos); + void leafVine_stitch_to(const Point &pos); + void squareZag_stitch_to(const Point &pos); + void satin_stitch_to(const Point &pos); + void check_density(const Point &pos); + void set_x(const float x); + void set_y(const float y); + void increment_x(const float x); + void increment_y(const float y); + // void rectangle(float w, float h); + // void circle(float radius); + // void snowflake(float sidelength, int levels); + // void flakeside(float sidelength, int levels); + // void squareSpiral(int line); + // void tree(int branch); + // void svtree(float trunklength, int levels, float trunkwidth); +private: + static const int DENSITY_PRECISION = 0; + static const int DENSITY_WARN_LIMIT = 15; + static const int DENSITY_ERROR_LIMIT = 20; + EmbPattern *emb_; + float stepsize_; + int color_; + bool pen_is_down_; + bool satin_is_on_; + float satin_delta_; + int decor_stitch_; + bool decor_active_; + Point dir_; + Point position_; + std::map density_; + bool density_error_; + bool density_warning_; }; #endif From d8ede7171006aca44fecdf32bbc46d02f1bfa7fd Mon Sep 17 00:00:00 2001 From: kittyk4t21 Date: Wed, 25 Oct 2023 16:17:32 -0700 Subject: [PATCH 2/6] added to comments added extra stitch to documentation for comments --- src/turtle.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/turtle.cpp b/src/turtle.cpp index 51c650c..9163c3d 100644 --- a/src/turtle.cpp +++ b/src/turtle.cpp @@ -79,6 +79,7 @@ Stitch Key * 2: Feather stitch * 3: Blanket stitch * 4: Leaf & Vine Stitch + * 5: Square Zag Stitch */ void Turtle::set_decor_stitch(int index) { @@ -93,6 +94,7 @@ void Turtle::set_decor_stitch(int index) * 2: Feather stitch * 3: Blanket stitch * 4: Leaf & Vine Stitch + * 5: Square Zag Stitch * */ void Turtle::decor_on(int index) From dc28cdc9cbff6863090cea0e18da51afe6711200 Mon Sep 17 00:00:00 2001 From: kittyk4t21 Date: Wed, 1 Nov 2023 16:26:17 -0700 Subject: [PATCH 3/6] added stitch lightning Lightning stitch, slanted zigzag-- also done so could separate out file changes (hopefully) --- src/turtle.cpp | 22 ++++++++++++++++++++++ src/turtle.hpp | 1 + 2 files changed, 23 insertions(+) diff --git a/src/turtle.cpp b/src/turtle.cpp index 9163c3d..f7072d4 100644 --- a/src/turtle.cpp +++ b/src/turtle.cpp @@ -80,6 +80,7 @@ Stitch Key * 3: Blanket stitch * 4: Leaf & Vine Stitch * 5: Square Zag Stitch + * 6: Lightning Stitch */ void Turtle::set_decor_stitch(int index) { @@ -95,6 +96,7 @@ void Turtle::set_decor_stitch(int index) * 3: Blanket stitch * 4: Leaf & Vine Stitch * 5: Square Zag Stitch + * 6: Lightning Stitch * */ void Turtle::decor_on(int index) @@ -273,6 +275,9 @@ void Turtle::gotopoint(const Point &pos) case 5: squareZag_stitch_to(pos); break; + case 6: + lightning_stitch_to(pos); + break; } } else @@ -600,6 +605,23 @@ void Turtle::squareZag_stitch_to(const Point &pos) stitch_abs(pos); } +void Turtle::lightning_stitch_to(const Point &pos) +{ + float total_length = (position_ - pos).length(); + size_t num_stitches = abs(int(total_length / stepsize_ / 2)); + + for (size_t i = 0; i < num_stitches; ++i) + { + left(30); + stitch(dir_ * (stepsize_ * 1.73)); + right(90); + stitch(dir_ * stepsize_); + left(60); + } + + stitch_abs(pos); +} + void Turtle::satin_stitch_to(const Point &pos) { float total_length = (position_ - pos).length(); diff --git a/src/turtle.hpp b/src/turtle.hpp index 9f8b8ce..aa3d09f 100644 --- a/src/turtle.hpp +++ b/src/turtle.hpp @@ -55,6 +55,7 @@ class Turtle void blanket_stitch_to(const Point &pos); void leafVine_stitch_to(const Point &pos); void squareZag_stitch_to(const Point &pos); + void lightning_stitch_to(const Point &pos); void satin_stitch_to(const Point &pos); void check_density(const Point &pos); void set_x(const float x); From 1989a9577683de87a29fe14b834d7e8df47d1f27 Mon Sep 17 00:00:00 2001 From: kittyk4t21 Date: Wed, 1 Nov 2023 16:46:18 -0700 Subject: [PATCH 4/6] demo changes testing --- demo/demo.cpp | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/demo/demo.cpp b/demo/demo.cpp index 58ad534..0afdb96 100644 --- a/demo/demo.cpp +++ b/demo/demo.cpp @@ -37,15 +37,19 @@ void meetTurtle() { Turtle t; // t.satinon(0.3); - // t.decor_on(0); + t.pendown(); - t.decor_on(5); - // t.forward(20); - // t.decor_on(4); - // rect(t, 30, 30); - t.setStepSize(10); + t.forward(10); + // t.decor_on(5); + t.decor_on(6); + t.forward(20); + t.decor_off(); + t.forward(10); + // t.decor_on(4); + // rect(t, 30, 30); + // penta(t, 50); - t.forward(60); + // t.forward(60); t.end(); t.save("demo.dst"); } From d3ffd4d0d6428abd56bbaa9c6afa37c6f9e3a4e2 Mon Sep 17 00:00:00 2001 From: kittyk4t21 Date: Fri, 3 Nov 2023 09:44:29 -0700 Subject: [PATCH 5/6] octa sampler octagon that samples different stitches --- demo/demo.cpp | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/demo/demo.cpp b/demo/demo.cpp index 0afdb96..e3d80f0 100644 --- a/demo/demo.cpp +++ b/demo/demo.cpp @@ -33,18 +33,37 @@ void penta(Turtle &t, float width) } } +void octa(Turtle &t, float width) +{ + + t.decor_on(0); + for (int i = 0; i < 8; i++) + { + if (i == 7) + { + t.decor_off(); + } + else + { + t.set_decor_stitch(i); + } + + t.forward(width); + t.left(45); + } +} + void meetTurtle() { Turtle t; // t.satinon(0.3); t.pendown(); - t.forward(10); - // t.decor_on(5); - t.decor_on(6); - t.forward(20); - t.decor_off(); - t.forward(10); + // t.forward(10); + // t.decor_on(5); + // t.decor_on(6); + + octa(t, 30); // t.decor_on(4); // rect(t, 30, 30); From c639f98fd0163162f2541c7442720de00cc8e677 Mon Sep 17 00:00:00 2001 From: kittyk4t21 Date: Fri, 3 Nov 2023 09:46:45 -0700 Subject: [PATCH 6/6] added documentation for size reccomended beginning step size for stitches --- src/turtle.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/turtle.cpp b/src/turtle.cpp index f7072d4..8ae4d63 100644 --- a/src/turtle.cpp +++ b/src/turtle.cpp @@ -73,6 +73,8 @@ void Turtle::satinoff() /* Sets the decorative stitch to be drawn with the turtle, does NOT turn it on though +For first test would reccomend step size of 10 for highly visible stitches, + stepsize 2 is very small and it makes it hard to see the decorative stitches Stitch Key * 0: Arrow stitch * 1: ZigZag stitch @@ -89,6 +91,10 @@ void Turtle::set_decor_stitch(int index) /** * Enables decorative stitches; sets stitch to stitch # passed in + * + * For first test would reccomend step size of 10 for highly visible stitches, + stepsize 2 is very small and it makes it hard to see the decorative stitches + * Stitch Key * 0: Arrow stitch * 1: ZigZag stitch