Skip to content

Instantly share code, notes, and snippets.

@W4RH4WK
Last active August 29, 2015 14:10
Show Gist options
  • Save W4RH4WK/2d5538b6f575602820a8 to your computer and use it in GitHub Desktop.
Save W4RH4WK/2d5538b6f575602820a8 to your computer and use it in GitHub Desktop.
parameterized OpenSCAD file for small containers
module insert(xcount, ycount, hspacer=0, vspacer=0, feet=true, side=47.55,
height=23, wall=1, cornerradius=4) {
x_space = side * xcount + 2 * (xcount - 1);
y_space = side * ycount + 2 * (ycount - 1);
x_corner = [
cornerradius,
x_space - cornerradius
];
y_corner = [
cornerradius,
y_space - cornerradius
];
module block() {
$fn = 24;
hull() {
for (x = x_corner, y = y_corner)
translate([x, y, 0])
cylinder(height, cornerradius / 2, cornerradius);
}
}
module empty() {
r = [
x_space - 2 * wall,
y_space - 2 * wall,
height
];
translate([wall, wall, wall])
resize(r)
block();
}
module spacer() {
union() {
if (hspacer != 0)
for (y = [1 : hspacer])
translate([0, y * (y_space - wall) / (hspacer + 1), wall])
cube([x_space, wall, height - wall]);
if (vspacer != 0)
for (x = [1 : vspacer])
translate([x * (x_space - wall) / (vspacer + 1), 0, wall])
cube([wall, y_space, height - wall]);
}
}
module feet() {
$fn = 24;
difference() {
for (x = x_corner, y = y_corner)
translate([x, y, - 2])
cylinder(2, cornerradius / 2 * height / (height + 2), cornerradius / 2);
translate([cornerradius, 0, - 2])
cube([x_space - 2 * cornerradius, y_space, 2]);
translate([0, cornerradius, - 2])
cube([x_space, y_space - 2 * cornerradius, 2]);
}
}
union() {
difference() {
block();
empty();
}
if (hspacer != 0 || vspacer != 0) {
intersection() {
spacer();
block();
}
}
if (feet)
feet();
}
}
insert(2, 1, 1, 0, true);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment