diff --git a/README.md b/README.md index 26b9da14..38d6934d 100644 --- a/README.md +++ b/README.md @@ -40,6 +40,7 @@ Some modules may depend on other modules. For example, the `polyline2d` module d - [function_grapher](https://openhome.cc/eGossip/OpenSCAD/lib-function_grapher.html) - Transformation + - [along_with](https://openhome.cc/eGossip/OpenSCAD/lib-along_with.html) - [hollow_out](https://openhome.cc/eGossip/OpenSCAD/lib-hollow_out.html) - [bend](https://openhome.cc/eGossip/OpenSCAD/lib-bend.html) diff --git a/docs/images/lib-along_with-1.JPG b/docs/images/lib-along_with-1.JPG new file mode 100644 index 00000000..39b6a196 Binary files /dev/null and b/docs/images/lib-along_with-1.JPG differ diff --git a/docs/images/lib-along_with-2.JPG b/docs/images/lib-along_with-2.JPG new file mode 100644 index 00000000..6f73b85e Binary files /dev/null and b/docs/images/lib-along_with-2.JPG differ diff --git a/docs/lib-along_with.md b/docs/lib-along_with.md new file mode 100644 index 00000000..bbcbf9f1 --- /dev/null +++ b/docs/lib-along_with.md @@ -0,0 +1,42 @@ +# along_with + +Puts children along the given path. If there's only one child, it will put the child for each point. + +## Parameters + +- `points` : The points along the path. + +## Examples + + include ; + include ; + + $fn = 24; + + points = circle_path(radius = 50); + + along_with(points) + sphere(5, center = true); + +![along_with](images/lib-along_with-1.JPG) + + include ; + include ; + + $fn = 24; + + points = circle_path(radius = 50); + + along_with(points) { + linear_extrude(10) text("A", valign = "center", halign = "center"); + linear_extrude(5) circle(2); + sphere(1); + cube(5); + linear_extrude(10) text("A", valign = "center", halign = "center"); + linear_extrude(5) circle(2); + sphere(1); + cube(5); + } + +![along_with](images/lib-along_with-2.JPG) + diff --git a/src/along_with.scad b/src/along_with.scad new file mode 100644 index 00000000..316fb27b --- /dev/null +++ b/src/along_with.scad @@ -0,0 +1,26 @@ +/** +* along_with.scad +* +* Puts children along the given path. If there's only one child, +* it will put the child for each point. +* +* @copyright Justin Lin, 2017 +* @license https://opensource.org/licenses/lgpl-3.0.html +* +* @see https://openhome.cc/eGossip/OpenSCAD/lib-along_with.html +* +**/ + +module along_with(points) { + if($children == 1) { + for(i = [0:len(points) - 1]) { + translate(points[i]) + children(0); + } + } else { + for(i = [0:min(len(points), $children) - 1]) { + translate(points[i]) + children(i); + } + } +} \ No newline at end of file