russelburgraymond

Untitled

Sep 10th, 2024
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.74 KB | Software | 0 0
  1. /* [Parameter] */
  2.  
  3. // size of the cards stack
  4. cardsize = [90, 65, 17];
  5.  
  6. // distance from card stack to wall
  7. xdist = 1;
  8. // wall thickness
  9. xwt = 1.6;
  10. // inner radius of edges
  11. xir = 2;
  12. // height of lid edge
  13. hh = 2;
  14. // quality of corners
  15. $fn = 50;
  16.  
  17. module qcircle(ir, or) {
  18. intersection() {
  19. square(or);
  20. difference() {
  21. circle(or);
  22. circle(ir);
  23. }
  24. }
  25. }
  26.  
  27. module qedge(ir, or, l) {
  28. linear_extrude(l) qcircle(ir, or);
  29. }
  30.  
  31. module qcorner(ir, or) {
  32. mirror([0, 0, 1]) rotate_extrude(angle = 90) qcircle(ir, or);
  33. }
  34.  
  35. module rsquare(wx, wy, ir, or) {
  36. translate([or, or]) difference() {
  37. offset(or) square([wx, wy]);
  38. offset(ir) square([wx, wy]);
  39. }
  40. }
  41.  
  42. module half_box(ibox, dist, wt, ir, th) {
  43. or = ir + wt;
  44.  
  45. bottombox = [ibox.x + dist * 2 - ir * 2, ibox.y + dist * 2 - ir * 2, wt];
  46.  
  47. color("blue") {
  48. // Front bottom edge
  49. translate([or, or, or]) rotate([-90, 0, -90]) qedge(ir, or, bottombox.x);
  50. // Back bottom edge
  51. translate([or, or + bottombox.y, or]) rotate([0, 90, 0]) qedge(ir, or, bottombox.x);
  52. // Right bottom edge
  53. translate([or + bottombox.x, or, or]) rotate([-90, 0, 0]) qedge(ir, or, bottombox.y);
  54. // Left bottom edge
  55. translate([or, or, or]) rotate([-90, 90, 0]) qedge(ir, or, bottombox.y);
  56. }
  57.  
  58. color("lightgreen") {
  59. translate([or, or, or]) rotate([0, 0, 180]) qcorner(ir, or);
  60. translate([bottombox.x + or, bottombox.y + or, or]) rotate([0, 0, 0]) qcorner(ir, or);
  61. translate([or, bottombox.y + or, or]) rotate([0, 0, 90]) qcorner(ir, or);
  62. translate([bottombox.x + or, or, or]) rotate([0, 0, -90]) qcorner(ir, or);
  63. }
  64.  
  65. // Show the cards stack in preview
  66. if ($preview) {
  67. translate([wt + dist, wt + dist, wt + dist]) color("#EEEEEE90") cube(ibox);
  68. }
  69.  
  70. // Main box
  71. color("red") translate([or, or, 0]) cube(bottombox);
  72. hlen = ibox.y / 2;
  73.  
  74. // Gripping grooves
  75. // Add groove for snapping mechanism
  76. translate([0, 0, or]) linear_extrude(ibox.z) rsquare(bottombox.x, bottombox.y, ir, or);
  77. mr = (ir + or) / 2;
  78.  
  79. if (th > 0) {
  80. translate([0, 0, or + ibox.z]) linear_extrude(th + 2) rsquare(bottombox.x, bottombox.y, mr, or); // Increased height by 2mm
  81. }
  82. if (th < 0) {
  83. dx = mr - ir;
  84. translate([dx, dx, or + ibox.z]) linear_extrude(-th) rsquare(bottombox.x, bottombox.y, ir, mr);
  85. }
  86. }
  87.  
  88. module text_with_transform(text, size, pos = [0, 0, 0], rot = [0, 0, 0], font = "Sans:style=Bold") {
  89. translate(pos) rotate(rot) {
  90. linear_extrude(height = -1)
  91. text(text, size = size, valign = "center", halign = "center", font = font);
  92. }
  93. }
  94.  
  95. module ridge(width, height, length) {
  96. translate([0, 0, -height])
  97. cube([width, length, height]);
  98. }
  99.  
  100. module groove(width, height, length) {
  101. translate([0, 0, -height])
  102. difference() {
  103. cube([width, length, height]);
  104. translate([1, 1, 0])
  105. cube([width - 2, length - 2, height + 1]);
  106. }
  107. }
  108.  
  109. // Parameters for text positioning and rotation
  110. text_pos = [0, 35, cardsize.z - 6]; // Position of the text
  111. text_rot = [90, 0, 270]; // Rotation of the text (in degrees)
  112.  
  113. // Design
  114. translate([0, 0, 0]) {
  115. // The real box
  116. half_box(ibox = cardsize, dist = xdist, wt = xwt, ir = xir, th = -hh);
  117.  
  118. // The cover
  119. translate([0, cardsize.y + 10, 0])
  120. half_box(ibox = [cardsize.x, cardsize.y, 3], dist = xdist, wt = xwt, ir = xir, th = +hh);
  121.  
  122. // Add the text "Cards" to the end of the box with rotation and translation
  123. difference(){
  124. union(){
  125. color("black")
  126. text_with_transform("Cards", 10, pos = text_pos, rot = text_rot);
  127. }
  128. }
  129. }
Advertisement
Add Comment
Please, Sign In to add comment