diff --git a/README.md b/README.md index 1fc9d2d6..4efe3ef1 100644 --- a/README.md +++ b/README.md @@ -210,6 +210,9 @@ See [examples](examples). - [util/sum](https://openhome.cc/eGossip/OpenSCAD/lib2x-sum.html) - [util/zip](https://openhome.cc/eGossip/OpenSCAD/lib2x-zip.html) +### Turtle +- [turtle/footprints2](https://openhome.cc/eGossip/OpenSCAD/lib2x-footprints2.html) + ---- ## Bugs and Feedback diff --git a/docs/lib2x-footprints2.md b/docs/lib2x-footprints2.md new file mode 100644 index 00000000..bea5d649 --- /dev/null +++ b/docs/lib2x-footprints2.md @@ -0,0 +1,54 @@ +# footprints2 + +Drive a turtle with `["forward", length]` or `["turn", angle]`. This function is intended to use a turtle to imitate freehand drawing. + +**Since:** 2.4 + +## Parameters + +- `cmds` : A list of `["forward", length]`s and `["turn", angle]`s. +- `start` : Set the start point of the turtle. + +## Examples + + use ; + use ; + + function arc_cmds(radius, angle, steps) = + let( + fa = angle / steps, + ta = fa / 2, + leng = sin(ta) * radius * 2 + ) + concat( + [["turn", ta]], + [ + for(i = [0:steps - 2]) + each [["forward", leng], ["turn", fa]] + ], + [["forward", leng], ["turn", ta]] + ); + + poly = footprints2( + concat( + [ + ["forward", 10], + ["turn", 90], + ["forward", 10] + ], + arc_cmds(5, 180, 12), + [ + ["turn", -90], + ["forward", 10], + ["turn", 90], + ["forward", 10], + ["turn", 90], + ["forward", 10] + ] + ) + ); + + polyline2d(poly, width = 1); + +![t3d](images/lib2x-footprints2-1.JPG) + diff --git a/src/turtle/footprints2.scad b/src/turtle/footprints2.scad index 0bb92dd1..0250ca21 100644 --- a/src/turtle/footprints2.scad +++ b/src/turtle/footprints2.scad @@ -1,51 +1,16 @@ -use ; +/** +* footprints2.scad +* +* @copyright Justin Lin, 2020 +* @license https://opensource.org/licenses/lgpl-3.0.html +* +* @see https://openhome.cc/eGossip/OpenSCAD/lib2x-footprints2.html +* +**/ + use <_impl/_footprints2.scad>; +use ; -/* - cmds: "turn", "forward" - -demo code -``` -use ; -use ; - -function arc_cmds(radius, angle, steps) = - let( - fa = angle / steps, - ta = fa / 2, - leng = sin(ta) * radius * 2 - ) - concat( - [["turn", ta]], - [ - for(i = [0:steps - 2]) - each [["forward", leng], ["turn", fa]] - ], - [["forward", leng], ["turn", ta]] - ); - -poly = footprints2( - concat( - [ - ["forward", 10], - ["turn", 90], - ["forward", 10] - ], - arc_cmds(5, 180, 12), - [ - ["turn", -90], - ["forward", 10], - ["turn", 90], - ["forward", 10], - ["turn", 90], - ["forward", 10] - ] - ) -); - -hull_polyline2d(poly, width = 1); -``` -*/ function footprints2(cmds, start = [0, 0]) = let( t = turtle2d("create", start[0], start[1], 0),