square.scad
1 use <../functions.scad> 2 3 // we do this weird key_shape_type check here because rounded_square uses 4 // square_shape, and we want flat sides to work for that too. 5 // could be refactored, idk 6 module square_shape(size, delta, progress){ 7 if ($key_shape_type == "flat_sided_square") { 8 flat_sided_square_shape(size, delta,progress); 9 } else { 10 square(size - delta * progress, center = true); 11 } 12 } 13 /* 14 [-size.x /2,-size.y / 2], 15 [size.x / 2,-size.y / 2], 16 [size.x / 2, size.y / 2], 17 [-size.x / 2, size.y / 2] */ 18 19 // for side-printed keycaps. Any amount of top tilt (on a keycap with a smaller 20 // top than bottom) makes the left and right side of the keycap convex. This 21 // shape makes the sides flat by making the top a trapezoid. 22 // This obviously doesn't work with rounded sides at all 23 module flat_sided_square_shape(size, delta, progress) { 24 polygon(skin_flat_sided_square_shape(size, delta, progress)); 25 } 26 27 function skin_flat_sided_square_shape(size,delta,progress) = [ 28 [(-size.x + (delta.x + extra_keytop_length_for_flat_sides()) * progress)/2, (-size.y + delta.y * progress)/2], 29 [(size.x - (delta.x + extra_keytop_length_for_flat_sides()) * progress)/2,(-size.y + delta.y * progress)/2], 30 [(size.x - (delta.x - extra_keytop_length_for_flat_sides()) * progress)/2, (size.y - delta.y * progress)/2], 31 [(-size.x + (delta.x - extra_keytop_length_for_flat_sides()) * progress)/2, (size.y - delta.y * progress)/2] 32 ]; 33 34 function rectangle_profile(size) = [ 35 [-size.x/2, -size.y/2], 36 [size.x/2, -size.y/2], 37 [size.x/2, size.y/2], 38 [-size.x/2, size.y/2], 39 ]; 40 41 function skin_square_shape(size, delta, progress, thickness_difference) = 42 let( 43 width = size[0], 44 height = size[1], 45 46 width_difference = delta[0] * progress, 47 height_difference = delta[1] * progress, 48 49 square_size = [ 50 width - width_difference - thickness_difference, 51 height - height_difference - thickness_difference 52 ] 53 ) $key_shape_type == "flat_sided_square" ? skin_flat_sided_square_shape(size, delta, progress) : rectangle_profile(square_size);