Skip to content

Instantly share code, notes, and snippets.

@joewalnes
Created January 10, 2012 01:55
Show Gist options
  • Save joewalnes/1586335 to your computer and use it in GitHub Desktop.
Save joewalnes/1586335 to your computer and use it in GitHub Desktop.
Toy brick generator, for OpenSCAD
// resolution of arcs.
$fs = 0.2;
module brick(units_long, units_wide) {
// dimensions (adjust for different brick systems)
piece_length = 5;
piece_height = 6;
wall_thickness = 1;
blob_height = 1;
// blob/tube radius - calculated from above dimensions
blob_radius = piece_length / 2 - wall_thickness;
tube_radius = sqrt(pow(piece_length / 2, 2) * 2) - blob_radius; // pythagatastic
// main brick shape
difference() {
// solid brick
cube([
units_long * piece_length,
units_wide * piece_length,
piece_height]);
// hollow out inside
translate([wall_thickness, wall_thickness, 0])
cube([
units_long * piece_length - wall_thickness * 2,
units_wide * piece_length - wall_thickness * 2,
piece_height - wall_thickness]);
}
// array of blobs on top
for (x = [0:units_long - 1]) {
for (y = [0:units_wide - 1]) {
translate([
x * piece_length + piece_length * 0.5,
y * piece_length + piece_length * 0.5,
piece_height])
difference() {
// blob
cylinder(h=blob_height, r=blob_radius);
// hollow center
cylinder(h=blob_height, r=blob_radius - wall_thickness);
}
}
}
// array of internal tubes that blobs press against
if (units_wide > 1 && units_long > 1) {
for (x = [1:units_long - 1]) {
for (y = [1:units_wide - 1]) {
translate([
x * piece_length /*+ piece_length * 0.5*/,
y * piece_length /*+ piece_length * 0.5*/,
0])
difference() {
// tube
cylinder(h=piece_height, r=tube_radius);
// hollow out
cylinder(h=piece_height, r=tube_radius - wall_thickness);
}
}
}
}
}
brick(2, 6);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment