/ examples / voronoi / voronoi_fibonacci.scad
voronoi_fibonacci.scad
 1  use <golden_spiral.scad>
 2  use <ptf/ptf_rotate.scad>
 3  use <hollow_out.scad>
 4  use <voronoi/vrn2_cells_from.scad>
 5  
 6  spirals = 2;     // [2:]
 7  line_thickness = .5;
 8  cell_thickness = 2;
 9  cell_top_scale = 0.8;
10  style = "BLOCK"; // [BLOCK, LINE]
11  
12  from = 5;
13  to = 8;
14  point_distance = 10;
15  
16  voronoi_fibonacci();
17  
18  module voronoi_fibonacci() {
19      points_angles = golden_spiral(
20          from = from, 
21          to = to, 
22          point_distance = point_distance
23      );
24      spiral = [for(pa = points_angles) pa[0]];
25      
26      a_step = 360 / spirals;
27  
28      pts = [
29          for(a = [0:a_step:360 - a_step])
30          each [for(p = spiral) ptf_rotate(p, a)]
31      ];
32          
33      half_line_thicness = line_thickness / 2;
34      lst_r = norm(spiral[len(spiral) - 1]) + half_line_thicness;
35  
36      cells = vrn2_cells_from(pts);    
37      for(i = [0:len(pts) - 1]) {
38          cell = cells[i];
39          
40          if(style == "BLOCK") {
41              pt = pts[i];
42              color(rands(0, 1, 3))
43              translate(pt)    
44              linear_extrude(cell_thickness, scale = cell_top_scale)
45              translate(-pt)    
46              intersection() {
47                  polygon(cell);
48                  circle(lst_r);
49              }        
50          }        
51          else {
52              linear_extrude(line_thickness) 
53              intersection() {
54                  hollow_out(half_line_thicness) polygon(cell);
55                  circle(lst_r);
56              }   
57          }
58      }
59      
60      linear_extrude(line_thickness) {
61          if(style == "BLOCK") {
62              circle(lst_r);
63          }
64          else {
65              hollow_out(line_thickness) 
66                  circle(lst_r);
67          }    
68      }
69  }