diff --git a/src/experimental/demo/lsystem2_demo.scad b/src/experimental/demo/lsystem2_demo.scad new file mode 100644 index 00000000..d43df97b --- /dev/null +++ b/src/experimental/demo/lsystem2_demo.scad @@ -0,0 +1,12 @@ +use ; +use ; + +for(line = sierpinski_square()) { + line2d( + line[0], + line[1], + .5, + p1Style = "CAP_ROUND", + p2Style = "CAP_ROUND" + ); +} \ No newline at end of file diff --git a/src/experimental/lsystem2_collections.scad b/src/experimental/lsystem2_collections.scad new file mode 100644 index 00000000..d9f22e1c --- /dev/null +++ b/src/experimental/lsystem2_collections.scad @@ -0,0 +1,214 @@ +use ; + +function tree(n = 2, angle = 36, leng = 1, heading = 0, start = [0, 0]) = + let( + rule = [ + ["S", "F"], + ["F", "F[+FF][-FF]F[-F][+F]F"] + ] + ) + lsystem2(rule, n, angle, leng, heading, start); + +function plant(n = 4, angle = 25, leng = 1, heading = 0, start = [0, 0]) = + let( + rule = [ + ["S", "X"], + ["X", "F+[[X]-X]-F[-FX]+X"], + ["F", "FF"] + ] + ) + lsystem2(rule, n, angle, leng, heading, start); + +function koch_curve(n = 4, angle = 60, leng = 1, heading = 0, start = [0, 0]) = + let( + rule = [ + ["S", "F"], + ["F", "F-F++F-F"] + ] + ) + lsystem2(rule, n, angle, leng, heading, start); + + +function koch_snowflake(n = 4, angle = 60, leng = 1, heading = 0, start = [0, 0]) = + let( + rule = [ + ["S", "F++F++F"], + ["F", "F-F++F-F"] + ] + ) + lsystem2(rule, n, angle, leng, heading, start); + +function koch_quadratic_type1(n = 4, angle = 90, leng = 1, heading = 0, start = [0, 0]) = + let( + rule = [ + ["S", "F"], + ["F", "F-F+F+F-F"] + ] + ) + lsystem2(rule, n, angle, leng, heading, start); + +function koch_quadratic_type2(n = 4, angle = 90, leng = 1, heading = 0, start = [0, 0]) = + let( + rule = [ + ["S", "F"], + ["F", "F-F+F+FF-F-F+F"] + ] + ) + lsystem2(rule, n, angle, leng, heading, start); + +function dragon_curve(n = 10, angle = 90, leng = 1, heading = 0, start = [0, 0]) = + let( + rule = [ + ["S", "FX"], + ["X", "X+YF+"], + ["Y", "-FX-Y"] + ] + ) + lsystem2(rule, n, angle, leng, heading, start); + +function twin_dragon_curve(n = 8, angle = 90, leng = 1, heading = 0, start = [0, 0]) = + let( + rule = [ + ["S", "FX+FX+"], + ["X", "X+YF"], + ["Y", "Y=FX-Y"] + ] + ) + lsystem2(rule, n, angle, leng, heading, start); + +function hilbert_curve(n = 5, angle = 90, leng = 1, heading = 0, start = [0, 0]) = + let( + rule = [ + ["S", "A"], + ["A", "-BF+AFA+FB-"], + ["B", "+AF-BFB-FA+"] + ] + ) + lsystem2(rule, n, angle, leng, heading, start); + +function moore_curve(n = 4, angle = 90, leng = 1, heading = 0, start = [0, 0]) = + let( + rule = [ + ["S", "LFL+F+LFL"], + ["L", "-RF+LFL+FR-"], + ["R", "+LF-RFR-FL+"] + ] + ) + lsystem2(rule, n, angle, leng, heading, start); + +function peano_curve(n = 3, angle = 90, leng = 1, heading = 0, start = [0, 0]) = + let( + rule = [ + ["S", "L"], + ["L", "LFRFL-F-RFLFR+F+LFRFL"], + ["R", "RFLFR+F+LFRFL-F-RFLFR"] + ] + ) + lsystem2(rule, n, angle, leng, heading, start); + +function gosper_curve(n = 4, angle = 60, leng = 1, heading = 0, start = [0, 0]) = + let( + rule = [ + ["S", "A"], + ["A", "A-B--B+A++AA+B-"], + ["B", "+A-BB--B-A++A+B"] + ] + ) + lsystem2(rule, n, angle, leng, heading, start, "AB"); + +function levy_c_curve(n = 8, angle = 45, leng = 1, heading = 0, start = [0, 0]) = + let( + rule = [ + ["S", "F"], + ["F", "+F--F+"] + ] + ) + lsystem2(rule, n, angle, leng, heading, start); + +function island_curve(n = 2, angle = 90, leng = 1, heading = 0, start = [0, 0]) = + let( + rule = [ + ["S", "F-F-F-F"], + ["F", "F-M+FF-F-FF-FM-FF+M-FF+F+FF+FM+FFF"], + ["M", "MMMMMM"] + ] + ) + lsystem2(rule, n, angle, leng, heading, start); + +function sierpinski_triangle(n = 5, angle = 120, leng = 1, heading = 0, start = [0, 0]) = + let( + rule = [ + ["S", "F-G-G"], + ["F", "F-G+F+G-F"], + ["G", "GG"] + ] + ) + lsystem2(rule, n, angle, leng, heading, start, "FG"); + +function sierpinski_arrowhead(n = 6, angle = 60, leng = 1, heading = 0, start = [0, 0]) = + let( + rule = [ + ["S", "XF"], + ["X", "YF+XF+Y"], + ["Y", "XF-YF-X"] + ] + ) + lsystem2(rule, n, angle, leng, heading, start, "FG"); + +function sierpinski_square(n = 8, angle = 45, leng = 1, heading = 0, start = [0, 0]) = + let( + rule = [ + ["S", "L--F--L--F"], + ["L", "+R-F-R+"], + ["R", "-L+F+L-"] + ] + ) + lsystem2(rule, n, angle, leng, heading, start, "FG"); + +function terdragon(n = 5, angle = 120, leng = 1, heading = 0, start = [0, 0]) = + let( + rule = [ + ["S", "F"], + ["F", "F+F-F"] + ] + ) + lsystem2(rule, n, angle, leng, heading, start); + +function pentadendrite(n = 2, angle = 72, leng = 1, heading = 0, start = [0, 0]) = + let( + rule = [ + ["S", "F-F-F-F-F"], + ["F", "F-F-F++F+F-F"] + ] + ) + lsystem2(rule, n, angle, leng, heading, start); + +function icy(n = 2, angle = 90, leng = 1, heading = 0, start = [0, 0]) = + let( + rule = [ + ["S", "F+F+F+F"], + ["F", "FF+F++F+F"] + ] + ) + lsystem2(rule, n, angle, leng, heading, start); + +function round_star(n = 3, angle = 77, leng = 1, heading = 0, start = [0, 0]) = + let( + rule = [ + ["S", "F"], + ["F", "F++F"] + ] + ) + lsystem2(rule, n, angle, leng, heading, start); + +function penrose_tiling(n = 2, angle = 36, leng = 1, heading = 0, start = [0, 0]) = + let( + rule = [ + ["S", "[7]++[7]++[7]++[7]++[7]"], + ["6", "81++91----71[-81----61]++"], + ["7", "+81--91[---61--71]+"], + ["8", "-61++71[+++81++91]-"], + ["9", "--81++++61[+91++++71]--71"] + ] + ) + lsystem2(rule, n, angle, leng, heading, start, "6789"); \ No newline at end of file