/ examples / dragon / hilbert_dragon_low_poly.scad
hilbert_dragon_low_poly.scad
 1  use <bezier_smooth.scad>
 2  use <bezier_curve.scad>
 3  use <ellipse_extrude.scad>
 4  use <path_extrude.scad>
 5  use <util/reverse.scad>
 6  use <util/dedup.scad>
 7  use <turtle/lsystem3.scad>
 8  use <dragon_head_low_poly.scad>
 9  
10  hilbert_dragon_low_poly();
11  
12  module hilbert_dragon_low_poly() {
13      lines = hilbert_curve();
14      hilbert_path = dedup([each [for(line = lines) line[0]], lines[len(lines) - 1][1]]);
15      smoothed_hilbert_path = bezier_smooth(hilbert_path, 0.48, t_step = 0.2);
16  
17      dragon_body_path = reverse([for(i = [1:len(smoothed_hilbert_path) - 4]) smoothed_hilbert_path[i]]);
18  
19      body_shape = concat(
20          bezier_curve(0.25, 
21              [
22                  [30, -35], [16, 0], [4, 13], 
23                  [3, -5], [0, 26], [-3, -5],
24                  [-4, 13],  [-16, 0], [-30, -35]
25              ]
26          ),
27          bezier_curve(0.25, 
28              [[-22, -35], [-15, -45], [0, -55], [15, -45], [22, -35]]
29          )
30      );    
31  
32      
33      pts = [for(p = body_shape) p * 0.007];
34      p = dragon_body_path[0];
35      
36      path_extrude(
37          pts, 
38          [p + [-.25, 0, -.05], each [for(i = [1:len(dragon_body_path) - 1]) dragon_body_path[i]]], 
39          scale = 0.9
40      );
41  
42      translate([0, 0, -2.81])        
43      scale(0.01)
44      rotate([-55, 0, 90]) 
45      dragon_head_low_poly(); 
46      
47      translate([0, 0, -0.525])
48      rotate([0, -7, 0])
49      rotate(90)
50      ellipse_extrude(0.5, slices = 4, twist = 15)
51      scale(0.9 * 0.007)
52          polygon(body_shape);
53  }
54     
55  
56  
57  function hilbert_curve() = 
58      let(
59          axiom = "A",
60          rules = [
61              ["A", "B-F+CFC+F-D&F^D-F+&&CFC+F+B//"],
62              ["B", "A&F^CFB^F^D^^-F-D^|F^B|FC^F^A//"],
63              ["C", "|D^|F^B-F+C^F^A&&FA&F^C+F+B^F^D//"],
64              ["D", "|CFB-F+B|FA&F^A&&FB-F+B|FC//"]
65          ]
66      )
67      lsystem3(axiom, rules, 2, 90, 1, 0,  [0, 0, 0]);