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:
parent
455887e906
commit
c2fe6ca4f9
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));
|
Loading…
x
Reference in New Issue
Block a user