/ examples / text_box.scad
text_box.scad
 1  use <box_extrude.scad>
 2  
 3  model_type = "Both"; // [Both, Lid, Container]
 4  t = "XD"; 
 5  font_size = 30;
 6  font_name = "Arial Black";
 7  r_round_edge = 7;
 8  container_height = 30;
 9  lid_height = 10;
10  thickness = 1;
11  spacing = 0.6;
12  
13  module minkowski_text(t, size, font, r_round_edge) {
14      $fn = 24;
15      minkowski() {
16          text(t, font = font, size = size);
17          circle(r_round_edge);
18      }
19  }
20  
21  module text_container(t, font_size, font_name, r_round_edge, container_height, thickness) {
22      box_extrude(height = container_height, shell_thickness = thickness) 
23          minkowski_text(t, font_size, font_name, r_round_edge);
24  }
25  
26  module text_lid(t, font_size, font_name, r_round_edge, lid_height, thickness, spacing) {
27      translate([0, 0, lid_height])
28      mirror([0, 0, 1])
29      box_extrude(height = lid_height, shell_thickness = thickness) 
30      mirror([0, 0, 1])
31      offset(r = spacing + thickness) 
32          minkowski_text(t, font_size, font_name, r_round_edge); 
33  }
34   
35  module text_box(model_type, t, font_size, font_name, r_round_edge, container_height, lid_height, thickness, spacing) {
36      if(model_type == "Both" || model_type == "Container") {
37          text_container(t, font_size, font_name, r_round_edge, container_height, thickness);    
38      }
39      
40      if(model_type == "Both" || model_type == "Lid") {
41          offset_y = (font_size + r_round_edge) * 2;
42  
43          translate([0, offset_y, 0]) 
44              text_lid(t, font_size, font_name, r_round_edge, lid_height, thickness, spacing);
45  
46          translate([0, offset_y, lid_height]) 
47              linear_extrude(thickness) 
48                  text(t, size = font_size, font = font_name);
49      }
50  }
51  
52  text_box(model_type, t, font_size, font_name, r_round_edge, container_height, lid_height, thickness, spacing);