diff --git a/src/turtle/_impl/_lsystem_comm.scad b/src/turtle/_impl/_lsystem_comm.scad index cdbd7f57..4a88a11c 100644 --- a/src/turtle/_impl/_lsystem_comm.scad +++ b/src/turtle/_impl/_lsystem_comm.scad @@ -24,16 +24,16 @@ function _join(str_lt) = let(leng = len(str_lt)) [for(i = 0, s = str_lt[0]; i < leng; i = i + 1, s = str(s, str_lt[i])) s][leng - 1]; -function c_or_v(c, v, rules, rules_pr, leng, seed, i = 0) = +function c_or_v(c, v, rules, rules_pr, leng, seed, ci, i = 0) = i == leng ? c : let(idx = search([v[i]], rules, num_returns_per_match=0, index_col_num = 1)[0][0]) - rand(0, 1, seed + i) <= rules_pr[idx] ? v[i] : c_or_v(c, v, rules, rules_pr, leng, seed, i + 1); + rand(0, 1, seed + ci + i) <= rules_pr[idx] ? v[i] : c_or_v(c, v, rules, rules_pr, leng, seed, ci, i + 1); function _derive1_p(base, rules, rules_pr, seed) = _join([ - for(c = base) - let(v = [for(r = rules) if(r[0] == c) r[1]]) - v == [] ? c : c_or_v(c, v, rules, rules_pr, len(v), seed) + for(ci = [0:len(base) - 1]) + let(c = base[ci], v = [for(r = rules) if(r[0] == c) r[1]]) + v == [] ? c : c_or_v(c, v, rules, rules_pr, len(v), seed, ci) ]); function _derive1(base, rules) = _join([