1
0
mirror of https://github.com/JustinSDK/dotSCAD.git synced 2025-08-17 20:11:50 +02:00

support forward_chars

This commit is contained in:
Justin Lin
2020-04-12 10:49:32 +08:00
parent 7684c94571
commit 7fe15d563d
2 changed files with 14 additions and 9 deletions

View File

@@ -6,17 +6,17 @@ function _join(strs) =
let(leng = len(strs)) let(leng = len(strs))
[for(i = 0, s = strs[0]; i < leng; i = i + 1, s = str(s, strs[i])) s][leng - 1]; [for(i = 0, s = strs[0]; i < leng; i = i + 1, s = str(s, strs[i])) s][leng - 1];
function _produce1(base, rule) = _join([ function _derive1(base, rule) = _join([
for(c = base) for(c = base)
let(v = assoc_lookup(rule, c)) let(v = assoc_lookup(rule, c))
is_undef(v) ? c : v is_undef(v) ? c : v
]); ]);
function _produce(base, rule, n, i = 0) = function _derive(base, rule, n, i = 0) =
i == n ? base : _produce(_produce1(base, rule), rule, n, i + 1); i == n ? base : _derive(_derive1(base, rule), rule, n, i + 1);
function produce(rule, n) = function derive(rule, n) =
_produce(assoc_lookup(rule, "S"), rule, n); _derive(assoc_lookup(rule, "S"), rule, n);
function cmd(symbol, args) = function cmd(symbol, args) =
symbol == "F" ? ["forward", args[0]] : symbol == "F" ? ["forward", args[0]] :

View File

@@ -1,16 +1,21 @@
use <experimental/_impl/_lsystem2_impl.scad>; use <experimental/_impl/_lsystem2_impl.scad>;
use <turtle/turtle2d.scad>; use <turtle/turtle2d.scad>;
function lsystem2(rule, n, angle, leng = 1, heading = 0, start_pt = [0, 0]) = function lsystem2(rule, n, angle, leng = 1, heading = 0, start = [0, 0], forward_chars = "F") =
let( let(
produced = produce(rule, n), derived = derive(rule, n),
replaced = _join([
for(c = derived)
let(idx = search(c, forward_chars))
idx == [] ? c : "F"
]),
cmds = [ cmds = [
for(s = produced) for(s = replaced)
let(c = cmd(s, [leng, angle])) let(c = cmd(s, [leng, angle]))
if(c != []) c if(c != []) c
] ]
) )
_lines( _lines(
turtle2d("create", start_pt[0], start_pt[0], heading), turtle2d("create", start[0], start[0], heading),
cmds cmds
); );