/ examples / turtle / lsystem2_collection.scad
lsystem2_collection.scad
  1  use <turtle/lsystem2.scad>
  2  use <util/dedup.scad>
  3  use <line2d.scad>
  4  
  5  for(line = dedup(fern())) {
  6      line2d(
  7          line[0],
  8          line[1],
  9          .2,
 10          p1Style = "CAP_ROUND", 
 11          p2Style =  "CAP_ROUND"
 12      );
 13  }
 14  
 15  function fern(n = 8, angle = 4, leng = 1, heading = 0, start = [0, 0]) = 
 16      let(
 17          axiom = "EEEA",
 18          rules = [
 19              ["A", "[++++++++++++++EC]B+B[--------------ED]B+BA"],
 20              ["C", "[---------EE][+++++++++EE]B+C"],
 21              ["D", "[---------EE][+++++++++EE]B-D"]
 22          ]
 23      )
 24      lsystem2(axiom, rules, n, angle, leng, heading, start, forward_chars = "ABCDE");  
 25  
 26  function tree(n = 2, angle = 36, leng = 1, heading = 0, start = [0, 0]) = 
 27      let(
 28          axiom = "F",
 29          rules = [
 30              ["F", "F[+FF][-FF]F[-F][+F]F"]
 31          ]
 32      )
 33      lsystem2(axiom, rules, n, angle, leng, heading, start);
 34  
 35  function plant(n = 4, angle = 25, leng = 1, heading = 0, start = [0, 0]) = 
 36      let(
 37          axiom = "X",
 38          rules = [
 39              ["X", "F+[[X]-X]-F[-FX]+X"],
 40              ["F", "FF"]
 41          ]
 42      )
 43      lsystem2(axiom, rules, n, angle, leng, heading, start);
 44  
 45  function koch_curve(n = 4, angle = 60, leng = 1, heading = 0, start = [0, 0]) = 
 46      let(
 47          axiom = "F",
 48          rules = [
 49              ["F", "F-F++F-F"]
 50          ]
 51      )
 52      lsystem2(axiom, rules, n, angle, leng, heading, start);
 53  
 54  function koch_curve_3(n = 3, angle = 90, leng = 1, heading = 0, start = [0, 0]) = 
 55      let(
 56          axiom = "F-F-F-F",
 57          rules = [
 58              ["F", "FF-F+F-F-FF"]
 59          ]
 60      )
 61      lsystem2(axiom, rules, n, angle, leng, heading, start);
 62  
 63  function koch_snowflake(n = 4, angle = 60, leng = 1, heading = 0, start = [0, 0]) = 
 64      let(
 65          axiom = "F++F++F",
 66          rules = [
 67              ["F", "F-F++F-F"]
 68          ]
 69      )
 70      lsystem2(axiom, rules, n, angle, leng, heading, start);
 71  
 72  function koch_quadratic(n = 3, angle = 90, leng = 1, heading = 0, start = [0, 0]) = 
 73      let(
 74          axiom = "F-F-F-F",
 75          rules = [
 76              ["F", "FF-F-F-F-F-F+F"]
 77          ]
 78      )
 79      lsystem2(axiom, rules, n, angle, leng, heading, start);
 80  
 81  function koch_quadratic_type1(n = 4, angle = 90, leng = 1, heading = 0, start = [0, 0]) = 
 82      let(
 83          axiom = "F",
 84          rules = [
 85              ["F", "F-F+F+F-F"]
 86          ]
 87      )
 88      lsystem2(axiom, rules, n, angle, leng, heading, start);
 89  
 90  function koch_quadratic_type2(n = 4, angle = 90, leng = 1, heading = 0, start = [0, 0]) = 
 91      let(
 92          axiom = "F",
 93          rules = [
 94              ["F", "F-F+F+FF-F-F+F"]
 95          ]
 96      )
 97      lsystem2(axiom, rules, n, angle, leng, heading, start);
 98  
 99  function koch_star(n = 4, angle = 60, leng = 1, heading = 0, start = [0, 0]) = 
100      let(
101          axiom = "F++F++F",
102          rules = [
103              ["F", "F+F--F+F"]
104          ]
105      )
106      lsystem2(axiom, rules, n, angle, leng, heading, start);   
107  
108  function dragon_curve(n = 10, angle = 90, leng = 1, heading = 0, start = [0, 0]) = 
109      let(
110          axiom = "FX",
111          rules = [
112              ["X", "X+YF+"],
113              ["Y", "-FX-Y"]
114          ]
115      )
116      lsystem2(axiom, rules, n, angle, leng, heading, start);
117  
118  function twin_dragon_curve(n = 8, angle = 90, leng = 1, heading = 0, start = [0, 0]) = 
119      let(
120          axiom = "FX+FX",
121          rules = [
122              ["X", "X+YF"],
123              ["Y", "FX-Y"]
124          ]
125      )
126      lsystem2(axiom, rules, n, angle, leng, heading, start);    
127  
128  function hilbert_curve(n = 5, angle = 90, leng = 1, heading = 0, start = [0, 0]) = 
129      let(
130          axiom = "A",
131          rules = [
132              ["A", "-BF+AFA+FB-"],
133              ["B", "+AF-BFB-FA+"]
134          ]
135      )
136      lsystem2(axiom, rules, n, angle, leng, heading, start);    
137  
138  function moore_curve(n = 4, angle = 90, leng = 1, heading = 0, start = [0, 0]) = 
139      let(
140          axiom = "LFL+F+LFL",
141          rules = [
142              ["L", "-RF+LFL+FR-"],
143              ["R", "+LF-RFR-FL+"]
144          ]
145      )
146      lsystem2(axiom, rules, n, angle, leng, heading, start);      
147  
148  function peano_curve(n = 3, angle = 90, leng = 1, heading = 0, start = [0, 0]) = 
149      let(
150          axiom = "L",
151          rules = [
152              ["L", "LFRFL-F-RFLFR+F+LFRFL"],
153              ["R", "RFLFR+F+LFRFL-F-RFLFR"]
154          ]
155      )
156      lsystem2(axiom, rules, n, angle, leng, heading, start);       
157  
158  function gosper_curve(n = 4, angle = 60, leng = 1, heading = 0, start = [0, 0]) = 
159      let(
160          axiom = "A",
161          rules = [
162              ["A", "A-B--B+A++AA+B-"],
163              ["B", "+A-BB--B-A++A+B"]
164          ]
165      )
166      lsystem2(axiom, rules, n, angle, leng, heading, start, "AB");    
167  
168  function gosper_star(n = 2, angle = 60, leng = 1, heading = 0, start = [0, 0]) = 
169      let(
170          axiom = "X-X-X-X-X-X",
171          rules = [
172              ["X", "FX+YF++YF-FX--FXFX-YF+"],
173              ["Y", "-FX+YFYF++YF+FX--FX-FY"]
174          ]
175      )
176      lsystem2(axiom, rules, n, angle, leng, heading, start);    
177  
178  function levy_c_curve(n = 8, angle = 45, leng = 1, heading = 0, start = [0, 0]) = 
179      let(
180          axiom = "F",
181          rules = [
182              ["F", "+F--F+"]
183          ]
184      )
185      lsystem2(axiom, rules, n, angle, leng, heading, start);       
186  
187  function island_curve(n = 2, angle = 90, leng = 1, heading = 0, start = [0, 0]) = 
188      let(
189          axiom = "F-F-F-F",
190          rules = [
191              ["F", "F-f+FF-F-FF-Ff-FF+f-FF+F+FF+Ff+FFF"],
192              ["f", "ffffff"]
193          ]
194      )
195      lsystem2(axiom, rules, n, angle, leng, heading, start);  
196  
197  function sierpinski_triangle(n = 5, angle = 120, leng = 1, heading = 0, start = [0, 0]) = 
198      let(
199          axiom = "F-G-G",
200          rules = [
201              ["F", "F-G+F+G-F"],
202              ["G", "GG"]
203          ]
204      )
205      lsystem2(axiom, rules, n, angle, leng, heading, start, "G");  
206  
207  function sierpinski_arrowhead(n = 6, angle = 60, leng = 1, heading = 0, start = [0, 0]) = 
208      let(
209          axiom = "XF",
210          rules = [
211              ["X", "YF+XF+Y"],
212              ["Y", "XF-YF-X"]
213          ]
214      )
215      lsystem2(axiom, rules, n, angle, leng, heading, start);     
216  
217  function sierpinski_square(n = 8, angle = 45, leng = 1, heading = 0, start = [0, 0]) = 
218      let(
219          axiom = "L--F--L--F",
220          rules = [
221              ["L", "+R-F-R+"],
222              ["R", "-L+F+L-"]
223          ]
224      )
225      lsystem2(axiom, rules, n, angle, leng, heading, start);      
226  
227  function sierpinski_carpet(n = 4, angle = 90, leng = 1, heading = 0, start = [0, 0]) = 
228      let(
229          axiom = "F",
230          rules = [
231              ["F", "F+F-F-F-G+F+F+F-F"],
232              ["G", "GGG"]
233          ]
234      )
235      lsystem2(axiom, rules, n, angle, leng, heading, start, forward_chars = "G");          
236  
237  function terdragon(n = 5, angle = 120, leng = 1, heading = 0, start = [0, 0]) = 
238      let(
239          axiom = "F",
240          rules = [
241              ["F", "F+F-F"]
242          ]
243      )
244      lsystem2(axiom, rules, n, angle, leng, heading, start);    
245  
246  function pentadendrite(n = 2, angle = 72, leng = 1, heading = 0, start = [0, 0]) = 
247      let(
248          axiom = "F-F-F-F-F",
249          rules = [
250              ["F", "F-F-F++F+F-F"]
251          ]
252      )
253      lsystem2(axiom, rules, n, angle, leng, heading, start);    
254  
255  function icy(n = 2, angle = 90, leng = 1, heading = 0, start = [0, 0]) = 
256      let(
257          axiom = "F+F+F+F",
258          rules = [
259              ["F", "FF+F++F+F"]
260          ]
261      )
262      lsystem2(axiom, rules, n, angle, leng, heading, start);        
263  
264  function round_star(n = 6, angle = 77, leng = 10, heading = 0, start = [0, 0]) = 
265      let(
266          axiom = "F",
267          rules = [
268              ["F", "F++F"]
269          ]
270      )
271      lsystem2(axiom, rules, n, angle, leng, heading, start);   
272  
273  function penrose_tiling(n = 2, angle = 36, leng = 1, heading = 0, start = [0, 0]) = 
274      let(
275          axiom = "[7]++[7]++[7]++[7]++[7]",
276          rules = [
277              ["6", "81++91----71[-81----61]++"],
278              ["7", "+81--91[---61--71]+"],
279              ["8", "-61++71[+++81++91]-"],
280              ["9", "--81++++61[+91++++71]--71"]
281          ]
282      )
283      lsystem2(axiom, rules, n, angle, leng, heading, start, "6789");       
284  
285  function bush(n = 3, angle = 16, leng = 1, heading = 0, start = [0, 0]) = 
286      let(
287          axiom = "++++F",
288          rules = [
289              ["F", "FF-[-F+F+F]+[+F-F-F]"]
290          ]
291      )
292      lsystem2(axiom, rules, n, angle, leng, heading, start);       
293  
294  function pentigree(n = 3, angle = 72, leng = 1, heading = 0, start = [0, 0]) = 
295      let(
296          axiom = "F-F-F-F-F",
297          rules = [
298              ["F", "F-F++F+F-F-F"]
299          ]
300      )
301      lsystem2(axiom, rules, n, angle, leng, heading, start);         
302  
303  function penrose_snowflake(n = 3, angle = 18, leng = 1, heading = 0, start = [0, 0]) = 
304      let(
305          axiom = "F----F----F----F----F",
306          rules = [
307              ["F", "F----F----F----------F++F----F"]
308          ]
309      )
310      lsystem2(axiom, rules, n, angle, leng, heading, start);         
311  
312  function weed(n = 6, angle = 22.5, leng = 1, heading = 0, start = [0, 0]) = 
313      let(
314          axiom = "F",
315          rules = [
316              ["F", "FF-[XY]+[XY]"],
317              ["X", "+FY"],
318              ["Y", "-FX"]
319          ]
320      )
321      lsystem2(axiom, rules, n, angle, leng, heading, start);
322  
323  function euler_spiral(n = 30, angle = 2.75, leng = 1, heading = 0, start = [0, 0]) = 
324      let(
325          axiom = "AF+",
326          rules = [
327              ["A", "AF+"],
328  			["F", "F+"]
329          ]
330      )
331      lsystem2(axiom, rules, n, angle, leng, heading, start);