mirror of
https://github.com/JustinSDK/dotSCAD.git
synced 2025-08-20 05:21:38 +02:00
add footprints2.scad
This commit is contained in:
9
src/turtle/_impl/_footprints2.scad
Normal file
9
src/turtle/_impl/_footprints2.scad
Normal 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);
|
56
src/turtle/footprints2.scad
Normal file
56
src/turtle/footprints2.scad
Normal 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));
|
Reference in New Issue
Block a user