1
0
mirror of https://github.com/JustinSDK/dotSCAD.git synced 2025-02-11 19:04:32 +01:00

add footprints2.scad

This commit is contained in:
Justin Lin 2020-05-09 09:59:50 +08:00
parent 455887e906
commit c2fe6ca4f9
2 changed files with 65 additions and 0 deletions

View File

@ -0,0 +1,9 @@
use <../turtle2d.scad>;
function _footprints2(cmds, t, leng, i = 0) =
i == leng ? [] :
let(
nxt = turtle2d(cmds[i][0], t, cmds[i][1]),
pts = _footprints2(cmds, nxt, leng, i + 1)
)
cmds[i][0] != "forward" ? pts : concat([turtle2d("pt", nxt)], pts);

View File

@ -0,0 +1,56 @@
use <turtle2d.scad>;
use <_impl/_footprints2.scad>;
/*
cmds: "turn", "forward"
demo code
```
use <turtle/footprints2.scad>;
use <hull_polyline2d.scad>;
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]
]
),
start = [10, 10],
angle = 90
);
hull_polyline2d(poly, width = 1);
```
*/
function footprints2(cmds, start = [0, 0], angle = 0) =
let(
t = turtle2d("create", start[0], start[1], angle),
leng = len(cmds)
)
concat([turtle2d("pt", t)], _footprints2(cmds, t, leng));