1
0
mirror of https://github.com/JustinSDK/dotSCAD.git synced 2025-08-12 17:54:18 +02:00

isolate axiom

This commit is contained in:
Justin Lin
2020-04-14 15:41:02 +08:00
parent 498f9f3e18
commit 05145694d9
3 changed files with 95 additions and 95 deletions

View File

@@ -13,287 +13,287 @@ for(line = plant()) {
function tree(n = 2, angle = 36, leng = 1, heading = 0, start = [0, 0]) = function tree(n = 2, angle = 36, leng = 1, heading = 0, start = [0, 0]) =
let( let(
rule = [ axiom = "F",
["S", "F"], rules = [
["F", "F[+FF][-FF]F[-F][+F]F"] ["F", "F[+FF][-FF]F[-F][+F]F"]
] ]
) )
lsystem2(rule, n, angle, leng, heading, start); lsystem2(axiom, rules, n, angle, leng, heading, start);
function plant(n = 4, angle = 25, leng = 1, heading = 0, start = [0, 0]) = function plant(n = 4, angle = 25, leng = 1, heading = 0, start = [0, 0]) =
let( let(
rule = [ axiom = "X",
["S", "X"], rules = [
["X", "F+[[X]-X]-F[-FX]+X"], ["X", "F+[[X]-X]-F[-FX]+X"],
["F", "FF"] ["F", "FF"]
] ]
) )
lsystem2(rule, n, angle, leng, heading, start); lsystem2(axiom, rules, n, angle, leng, heading, start);
function koch_curve(n = 4, angle = 60, leng = 1, heading = 0, start = [0, 0]) = function koch_curve(n = 4, angle = 60, leng = 1, heading = 0, start = [0, 0]) =
let( let(
rule = [ axiom = "F",
["S", "F"], rules = [
["F", "F-F++F-F"] ["F", "F-F++F-F"]
] ]
) )
lsystem2(rule, n, angle, leng, heading, start); lsystem2(axiom, rules, n, angle, leng, heading, start);
function koch_curve_3(n = 3, angle = 90, leng = 1, heading = 0, start = [0, 0]) = function koch_curve_3(n = 3, angle = 90, leng = 1, heading = 0, start = [0, 0]) =
let( let(
rule = [ axiom = "F-F-F-F",
["S", "F-F-F-F"], rules = [
["F", "FF-F+F-F-FF"] ["F", "FF-F+F-F-FF"]
] ]
) )
lsystem2(rule, n, angle, leng, heading, start); lsystem2(axiom, rules, n, angle, leng, heading, start);
function koch_snowflake(n = 4, angle = 60, leng = 1, heading = 0, start = [0, 0]) = function koch_snowflake(n = 4, angle = 60, leng = 1, heading = 0, start = [0, 0]) =
let( let(
rule = [ axiom = "F++F++F",
["S", "F++F++F"], rules = [
["F", "F-F++F-F"] ["F", "F-F++F-F"]
] ]
) )
lsystem2(rule, n, angle, leng, heading, start); lsystem2(axiom, rules, n, angle, leng, heading, start);
function koch_quadratic(n = 3, angle = 90, leng = 1, heading = 0, start = [0, 0]) = function koch_quadratic(n = 3, angle = 90, leng = 1, heading = 0, start = [0, 0]) =
let( let(
rule = [ axiom = "F-F-F-F",
["S", "F-F-F-F"], rules = [
["F", "FF-F-F-F-F-F+F"] ["F", "FF-F-F-F-F-F+F"]
] ]
) )
lsystem2(rule, n, angle, leng, heading, start); lsystem2(axiom, rules, n, angle, leng, heading, start);
function koch_quadratic_type1(n = 4, angle = 90, leng = 1, heading = 0, start = [0, 0]) = function koch_quadratic_type1(n = 4, angle = 90, leng = 1, heading = 0, start = [0, 0]) =
let( let(
rule = [ axiom = "F",
["S", "F"], rules = [
["F", "F-F+F+F-F"] ["F", "F-F+F+F-F"]
] ]
) )
lsystem2(rule, n, angle, leng, heading, start); lsystem2(axiom, rules, n, angle, leng, heading, start);
function koch_quadratic_type2(n = 4, angle = 90, leng = 1, heading = 0, start = [0, 0]) = function koch_quadratic_type2(n = 4, angle = 90, leng = 1, heading = 0, start = [0, 0]) =
let( let(
rule = [ axiom = "F",
["S", "F"], rules = [
["F", "F-F+F+FF-F-F+F"] ["F", "F-F+F+FF-F-F+F"]
] ]
) )
lsystem2(rule, n, angle, leng, heading, start); lsystem2(axiom, rules, n, angle, leng, heading, start);
function koch_star(n = 4, angle = 60, leng = 1, heading = 0, start = [0, 0]) = function koch_star(n = 4, angle = 60, leng = 1, heading = 0, start = [0, 0]) =
let( let(
rule = [ axiom = "F++F++F",
["S", "F++F++F"], rules = [
["F", "F+F--F+F"] ["F", "F+F--F+F"]
] ]
) )
lsystem2(rule, n, angle, leng, heading, start, "6789"); lsystem2(axiom, rules, n, angle, leng, heading, start, "6789");
function dragon_curve(n = 10, angle = 90, leng = 1, heading = 0, start = [0, 0]) = function dragon_curve(n = 10, angle = 90, leng = 1, heading = 0, start = [0, 0]) =
let( let(
rule = [ axiom = "FX",
["S", "FX"], rules = [
["X", "X+YF+"], ["X", "X+YF+"],
["Y", "-FX-Y"] ["Y", "-FX-Y"]
] ]
) )
lsystem2(rule, n, angle, leng, heading, start); lsystem2(axiom, rules, n, angle, leng, heading, start);
function twin_dragon_curve(n = 8, angle = 90, leng = 1, heading = 0, start = [0, 0]) = function twin_dragon_curve(n = 8, angle = 90, leng = 1, heading = 0, start = [0, 0]) =
let( let(
rule = [ axiom = "FX+FX+",
["S", "FX+FX+"], rules = [
["X", "X+YF"], ["X", "X+YF"],
["Y", "Y=FX-Y"] ["Y", "Y=FX-Y"]
] ]
) )
lsystem2(rule, n, angle, leng, heading, start); lsystem2(axiom, rules, n, angle, leng, heading, start);
function hilbert_curve(n = 5, angle = 90, leng = 1, heading = 0, start = [0, 0]) = function hilbert_curve(n = 5, angle = 90, leng = 1, heading = 0, start = [0, 0]) =
let( let(
rule = [ axiom = "A",
["S", "A"], rules = [
["A", "-BF+AFA+FB-"], ["A", "-BF+AFA+FB-"],
["B", "+AF-BFB-FA+"] ["B", "+AF-BFB-FA+"]
] ]
) )
lsystem2(rule, n, angle, leng, heading, start); lsystem2(axiom, rules, n, angle, leng, heading, start);
function moore_curve(n = 4, angle = 90, leng = 1, heading = 0, start = [0, 0]) = function moore_curve(n = 4, angle = 90, leng = 1, heading = 0, start = [0, 0]) =
let( let(
rule = [ axiom = "LFL+F+LFL",
["S", "LFL+F+LFL"], rules = [
["L", "-RF+LFL+FR-"], ["L", "-RF+LFL+FR-"],
["R", "+LF-RFR-FL+"] ["R", "+LF-RFR-FL+"]
] ]
) )
lsystem2(rule, n, angle, leng, heading, start); lsystem2(axiom, rules, n, angle, leng, heading, start);
function peano_curve(n = 3, angle = 90, leng = 1, heading = 0, start = [0, 0]) = function peano_curve(n = 3, angle = 90, leng = 1, heading = 0, start = [0, 0]) =
let( let(
rule = [ axiom = "L",
["S", "L"], rules = [
["L", "LFRFL-F-RFLFR+F+LFRFL"], ["L", "LFRFL-F-RFLFR+F+LFRFL"],
["R", "RFLFR+F+LFRFL-F-RFLFR"] ["R", "RFLFR+F+LFRFL-F-RFLFR"]
] ]
) )
lsystem2(rule, n, angle, leng, heading, start); lsystem2(axiom, rules, n, angle, leng, heading, start);
function gosper_curve(n = 4, angle = 60, leng = 1, heading = 0, start = [0, 0]) = function gosper_curve(n = 4, angle = 60, leng = 1, heading = 0, start = [0, 0]) =
let( let(
rule = [ axiom = "A",
["S", "A"], rules = [
["A", "A-B--B+A++AA+B-"], ["A", "A-B--B+A++AA+B-"],
["B", "+A-BB--B-A++A+B"] ["B", "+A-BB--B-A++A+B"]
] ]
) )
lsystem2(rule, n, angle, leng, heading, start, "AB"); lsystem2(axiom, rules, n, angle, leng, heading, start, "AB");
function gosper_star(n = 2, angle = 60, leng = 1, heading = 0, start = [0, 0]) = function gosper_star(n = 2, angle = 60, leng = 1, heading = 0, start = [0, 0]) =
let( let(
rule = [ axiom = "X-X-X-X-X-X",
["S", "X-X-X-X-X-X"], rules = [
["X", "FX+YF++YF-FX--FXFX-YF+"], ["X", "FX+YF++YF-FX--FXFX-YF+"],
["Y", "-FX+YFYF++YF+FX--FX-FY"] ["Y", "-FX+YFYF++YF+FX--FX-FY"]
] ]
) )
lsystem2(rule, n, angle, leng, heading, start); lsystem2(axiom, rules, n, angle, leng, heading, start);
function levy_c_curve(n = 8, angle = 45, leng = 1, heading = 0, start = [0, 0]) = function levy_c_curve(n = 8, angle = 45, leng = 1, heading = 0, start = [0, 0]) =
let( let(
rule = [ axiom = "F",
["S", "F"], rules = [
["F", "+F--F+"] ["F", "+F--F+"]
] ]
) )
lsystem2(rule, n, angle, leng, heading, start); lsystem2(axiom, rules, n, angle, leng, heading, start);
function island_curve(n = 2, angle = 90, leng = 1, heading = 0, start = [0, 0]) = function island_curve(n = 2, angle = 90, leng = 1, heading = 0, start = [0, 0]) =
let( let(
rule = [ axiom = "F-F-F-F",
["S", "F-F-F-F"], rules = [
["F", "F-M+FF-F-FF-FM-FF+M-FF+F+FF+FM+FFF"], ["F", "F-M+FF-F-FF-FM-FF+M-FF+F+FF+FM+FFF"],
["M", "MMMMMM"] ["M", "MMMMMM"]
] ]
) )
lsystem2(rule, n, angle, leng, heading, start); lsystem2(axiom, rules, n, angle, leng, heading, start);
function sierpinski_triangle(n = 5, angle = 120, leng = 1, heading = 0, start = [0, 0]) = function sierpinski_triangle(n = 5, angle = 120, leng = 1, heading = 0, start = [0, 0]) =
let( let(
rule = [ axiom = "F-G-G",
["S", "F-G-G"], rules = [
["F", "F-G+F+G-F"], ["F", "F-G+F+G-F"],
["G", "GG"] ["G", "GG"]
] ]
) )
lsystem2(rule, n, angle, leng, heading, start, "FG"); lsystem2(axiom, rules, n, angle, leng, heading, start, "FG");
function sierpinski_arrowhead(n = 6, angle = 60, leng = 1, heading = 0, start = [0, 0]) = function sierpinski_arrowhead(n = 6, angle = 60, leng = 1, heading = 0, start = [0, 0]) =
let( let(
rule = [ axiom = "XF",
["S", "XF"], rules = [
["X", "YF+XF+Y"], ["X", "YF+XF+Y"],
["Y", "XF-YF-X"] ["Y", "XF-YF-X"]
] ]
) )
lsystem2(rule, n, angle, leng, heading, start); lsystem2(axiom, rules, n, angle, leng, heading, start);
function sierpinski_square(n = 8, angle = 45, leng = 1, heading = 0, start = [0, 0]) = function sierpinski_square(n = 8, angle = 45, leng = 1, heading = 0, start = [0, 0]) =
let( let(
rule = [ axiom = "L--F--L--F",
["S", "L--F--L--F"], rules = [
["L", "+R-F-R+"], ["L", "+R-F-R+"],
["R", "-L+F+L-"] ["R", "-L+F+L-"]
] ]
) )
lsystem2(rule, n, angle, leng, heading, start); lsystem2(axiom, rules, n, angle, leng, heading, start);
function terdragon(n = 5, angle = 120, leng = 1, heading = 0, start = [0, 0]) = function terdragon(n = 5, angle = 120, leng = 1, heading = 0, start = [0, 0]) =
let( let(
rule = [ axiom = "F",
["S", "F"], rules = [
["F", "F+F-F"] ["F", "F+F-F"]
] ]
) )
lsystem2(rule, n, angle, leng, heading, start); lsystem2(axiom, rules, n, angle, leng, heading, start);
function pentadendrite(n = 2, angle = 72, leng = 1, heading = 0, start = [0, 0]) = function pentadendrite(n = 2, angle = 72, leng = 1, heading = 0, start = [0, 0]) =
let( let(
rule = [ axiom = "F-F-F-F-F",
["S", "F-F-F-F-F"], rules = [
["F", "F-F-F++F+F-F"] ["F", "F-F-F++F+F-F"]
] ]
) )
lsystem2(rule, n, angle, leng, heading, start); lsystem2(axiom, rules, n, angle, leng, heading, start);
function icy(n = 2, angle = 90, leng = 1, heading = 0, start = [0, 0]) = function icy(n = 2, angle = 90, leng = 1, heading = 0, start = [0, 0]) =
let( let(
rule = [ axiom = "F+F+F+F",
["S", "F+F+F+F"], rules = [
["F", "FF+F++F+F"] ["F", "FF+F++F+F"]
] ]
) )
lsystem2(rule, n, angle, leng, heading, start); lsystem2(axiom, rules, n, angle, leng, heading, start);
function round_star(n = 3, angle = 77, leng = 1, heading = 0, start = [0, 0]) = function round_star(n = 3, angle = 77, leng = 1, heading = 0, start = [0, 0]) =
let( let(
rule = [ axiom = "F",
["S", "F"], rules = [
["F", "F++F"] ["F", "F++F"]
] ]
) )
lsystem2(rule, n, angle, leng, heading, start); lsystem2(axiom, rules, n, angle, leng, heading, start);
function penrose_tiling(n = 2, angle = 36, leng = 1, heading = 0, start = [0, 0]) = function penrose_tiling(n = 2, angle = 36, leng = 1, heading = 0, start = [0, 0]) =
let( let(
rule = [ axiom = "[7]++[7]++[7]++[7]++[7]",
["S", "[7]++[7]++[7]++[7]++[7]"], rules = [
["6", "81++91----71[-81----61]++"], ["6", "81++91----71[-81----61]++"],
["7", "+81--91[---61--71]+"], ["7", "+81--91[---61--71]+"],
["8", "-61++71[+++81++91]-"], ["8", "-61++71[+++81++91]-"],
["9", "--81++++61[+91++++71]--71"] ["9", "--81++++61[+91++++71]--71"]
] ]
) )
lsystem2(rule, n, angle, leng, heading, start, "6789"); lsystem2(axiom, rules, n, angle, leng, heading, start, "6789");
function bush(n = 3, angle = 16, leng = 1, heading = 0, start = [0, 0]) = function bush(n = 3, angle = 16, leng = 1, heading = 0, start = [0, 0]) =
let( let(
rule = [ axiom = "++++F",
["S", "++++F"], rules = [
["F", "FF-[-F+F+F]+[+F-F-F]"] ["F", "FF-[-F+F+F]+[+F-F-F]"]
] ]
) )
lsystem2(rule, n, angle, leng, heading, start); lsystem2(axiom, rules, n, angle, leng, heading, start);
function pentigree(n = 3, angle = 72, leng = 1, heading = 0, start = [0, 0]) = function pentigree(n = 3, angle = 72, leng = 1, heading = 0, start = [0, 0]) =
let( let(
rule = [ axiom = "F-F-F-F-F",
["S", "F-F-F-F-F"], rules = [
["F", "F-F++F+F-F-F"] ["F", "F-F++F+F-F-F"]
] ]
) )
lsystem2(rule, n, angle, leng, heading, start); lsystem2(axiom, rules, n, angle, leng, heading, start);
function penrose_snowflake(n = 3, angle = 18, leng = 1, heading = 0, start = [0, 0]) = function penrose_snowflake(n = 3, angle = 18, leng = 1, heading = 0, start = [0, 0]) =
let( let(
rule = [ axiom = "F----F----F----F----F",
["S", "F----F----F----F----F"], rules = [
["F", "F----F----F----------F++F----F"] ["F", "F----F----F----------F++F----F"]
] ]
) )
lsystem2(rule, n, angle, leng, heading, start); lsystem2(axiom, rules, n, angle, leng, heading, start);
function weed(n = 6, angle = 22.5, leng = 1, heading = 0, start = [0, 0]) = function weed(n = 6, angle = 22.5, leng = 1, heading = 0, start = [0, 0]) =
let( let(
rule = [ axiom = "F",
["S", "F"], rules = [
["F", "FF-[XY]+[XY]"], ["F", "FF-[XY]+[XY]"],
["X", "+FY"], ["X", "+FY"],
["Y", "-FX"] ["Y", "-FX"]
] ]
) )
lsystem2(rule, n, angle, leng, heading, start); lsystem2(axiom, rules, n, angle, leng, heading, start);

View File

@@ -33,9 +33,9 @@ function _derive1(base, rules) = _join([
function _derive(base, rules, n, i = 0) = function _derive(base, rules, n, i = 0) =
i == n ? base : _derive(_derive1(base, rules), rules, n, i + 1); i == n ? base : _derive(_derive1(base, rules), rules, n, i + 1);
function _lsystem2_derive(rules, n, rules_pr) = function _lsystem2_derive(axiom, rules, n, rules_pr) =
is_undef(rules_pr) ? _derive(rules[0][1], rules, n) : is_undef(rules_pr) ? _derive(axiom, rules, n) :
rand() <= rules_pr[0] ? _derive_p(rules[0][1], rules, rules_pr, n) : ""; _derive_p(axiom, rules, rules_pr, n);
function _next_stack(t, code, stack) = function _next_stack(t, code, stack) =
code == "[" ? concat([t], stack) : code == "[" ? concat([t], stack) :

View File

@@ -1,9 +1,9 @@
use <experimental/_impl/_lsystem2_impl.scad>; use <experimental/_impl/_lsystem2_impl.scad>;
use <turtle/turtle2d.scad>; use <turtle/turtle2d.scad>;
function lsystem2(rules, n, angle, leng = 1, heading = 0, start = [0, 0], forward_chars = "F", rules_pr) = function lsystem2(axiom, rules, n, angle, leng = 1, heading = 0, start = [0, 0], forward_chars = "F", rules_pr) =
let( let(
derived = _lsystem2_derive(rules, n, rules_pr), derived = _lsystem2_derive(axiom, rules, n, rules_pr),
codes = forward_chars == "F" ? derived : _join([ codes = forward_chars == "F" ? derived : _join([
for(c = derived) for(c = derived)
let(idx = search(c, forward_chars)) let(idx = search(c, forward_chars))