/ src / supports / flared.scad
flared.scad
 1  include <../functions.scad>
 2  // TODO this define doesn't do anything besides tell me I used flat() in this file
 3  // is it better than not having it at all?
 4  include <./flat.scad>
 5  
 6  // figures out the scale factor needed to make a 45 degree wall
 7  function scale_for_45(height, starting_size) = (height * 2 + starting_size) / starting_size;
 8  
 9  // complicated since we want the different stems to work well
10  // also kind of messy... oh well
11  module flared(stem_type, loft, height) {
12    // flat support. straight flat support has a tendency to shear off; flared support
13    // all the way to the top has a tendency to warp the outside of the keycap.
14    // hopefully the compromise is both
15    flat(stem_type, loft + height/4, height);
16  
17    translate([0,0,loft]){
18      if (stem_type == "rounded_cherry") {
19        linear_extrude(height=height, scale = scale_for_45(height, $rounded_cherry_stem_d)){
20          circle(d=$rounded_cherry_stem_d);
21        }
22      } else if (stem_type == "alps") {
23        alps_scale = [scale_for_45(height, $alps_stem[0]), scale_for_45(height, $alps_stem[1])];
24        linear_extrude(height=height, scale = alps_scale){
25          square($alps_stem, center=true);
26        }
27      } else if (stem_type == "box_cherry") {
28        // always render cherry if no stem type. this includes stem_type = false!
29        // this avoids a bug where the keycap is rendered filled when not desired
30        cherry_scale = [scale_for_45(height, outer_box_cherry_stem($stem_slop)[0]), scale_for_45(height, outer_box_cherry_stem($stem_slop)[1])];
31        linear_extrude(height=height, scale = cherry_scale){
32          offset(r=1){
33            square(outer_box_cherry_stem($stem_slop) - [2,2], center=true);
34          }
35        }
36      } else if (stem_type == "cherry_stabilizer") {
37        cherry_scale = [scale_for_45(height, outer_cherry_stabilizer_stem($stem_slop)[0]), scale_for_45(height, outer_cherry_stabilizer_stem($stem_slop)[1])];
38        linear_extrude(height=height, scale = cherry_scale){
39          offset(r=1){
40            square(outer_cherry_stabilizer_stem($stem_slop) - [2,2], center=true);
41          }
42        }
43      } else {
44        // always render cherry if no stem type. this includes stem_type = false!
45        // this avoids a bug where the keycap is rendered filled when not desired
46        cherry_scale = [scale_for_45(height, outer_cherry_stem($stem_slop)[0]), scale_for_45(height, outer_cherry_stem($stem_slop)[1])];
47        linear_extrude(height=height, scale = cherry_scale){
48          offset(r=1){
49            square(outer_cherry_stem($stem_slop) - [2,2], center=true);
50          }
51        }
52      }
53    }
54  }