Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* [Parameter] */
- // size of the cards stack
- cardsize = [90, 65, 17];
- // distance from card stack to wall
- xdist = 1;
- // wall thickness
- xwt = 1.6;
- // inner radius of edges
- xir = 2;
- // height of lid edge
- hh = 2;
- // quality of corners
- $fn = 50;
- module qcircle(ir, or) {
- intersection() {
- square(or);
- difference() {
- circle(or);
- circle(ir);
- }
- }
- }
- module qedge(ir, or, l) {
- linear_extrude(l) qcircle(ir, or);
- }
- module qcorner(ir, or) {
- mirror([0, 0, 1]) rotate_extrude(angle = 90) qcircle(ir, or);
- }
- module rsquare(wx, wy, ir, or) {
- translate([or, or]) difference() {
- offset(or) square([wx, wy]);
- offset(ir) square([wx, wy]);
- }
- }
- module half_box(ibox, dist, wt, ir, th) {
- or = ir + wt;
- bottombox = [ibox.x + dist * 2 - ir * 2, ibox.y + dist * 2 - ir * 2, wt];
- color("blue") {
- // Front bottom edge
- translate([or, or, or]) rotate([-90, 0, -90]) qedge(ir, or, bottombox.x);
- // Back bottom edge
- translate([or, or + bottombox.y, or]) rotate([0, 90, 0]) qedge(ir, or, bottombox.x);
- // Right bottom edge
- translate([or + bottombox.x, or, or]) rotate([-90, 0, 0]) qedge(ir, or, bottombox.y);
- // Left bottom edge
- translate([or, or, or]) rotate([-90, 90, 0]) qedge(ir, or, bottombox.y);
- }
- color("lightgreen") {
- translate([or, or, or]) rotate([0, 0, 180]) qcorner(ir, or);
- translate([bottombox.x + or, bottombox.y + or, or]) rotate([0, 0, 0]) qcorner(ir, or);
- translate([or, bottombox.y + or, or]) rotate([0, 0, 90]) qcorner(ir, or);
- translate([bottombox.x + or, or, or]) rotate([0, 0, -90]) qcorner(ir, or);
- }
- // Show the cards stack in preview
- if ($preview) {
- translate([wt + dist, wt + dist, wt + dist]) color("#EEEEEE90") cube(ibox);
- }
- // Main box
- color("red") translate([or, or, 0]) cube(bottombox);
- hlen = ibox.y / 2;
- // Gripping grooves
- // Add groove for snapping mechanism
- translate([0, 0, or]) linear_extrude(ibox.z) rsquare(bottombox.x, bottombox.y, ir, or);
- mr = (ir + or) / 2;
- if (th > 0) {
- translate([0, 0, or + ibox.z]) linear_extrude(th + 2) rsquare(bottombox.x, bottombox.y, mr, or); // Increased height by 2mm
- }
- if (th < 0) {
- dx = mr - ir;
- translate([dx, dx, or + ibox.z]) linear_extrude(-th) rsquare(bottombox.x, bottombox.y, ir, mr);
- }
- }
- module text_with_transform(text, size, pos = [0, 0, 0], rot = [0, 0, 0], font = "Sans:style=Bold") {
- translate(pos) rotate(rot) {
- linear_extrude(height = -1)
- text(text, size = size, valign = "center", halign = "center", font = font);
- }
- }
- module ridge(width, height, length) {
- translate([0, 0, -height])
- cube([width, length, height]);
- }
- module groove(width, height, length) {
- translate([0, 0, -height])
- difference() {
- cube([width, length, height]);
- translate([1, 1, 0])
- cube([width - 2, length - 2, height + 1]);
- }
- }
- // Parameters for text positioning and rotation
- text_pos = [0, 35, cardsize.z - 6]; // Position of the text
- text_rot = [90, 0, 270]; // Rotation of the text (in degrees)
- // Design
- translate([0, 0, 0]) {
- // The real box
- half_box(ibox = cardsize, dist = xdist, wt = xwt, ir = xir, th = -hh);
- // The cover
- translate([0, cardsize.y + 10, 0])
- half_box(ibox = [cardsize.x, cardsize.y, 3], dist = xdist, wt = xwt, ir = xir, th = +hh);
- // Add the text "Cards" to the end of the box with rotation and translation
- difference(){
- union(){
- color("black")
- text_with_transform("Cards", 10, pos = text_pos, rot = text_rot);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment