Skip to content

Instantly share code, notes, and snippets.

@lorennorman
Created December 29, 2011 17:02
Show Gist options
  • Save lorennorman/1534990 to your computer and use it in GitHub Desktop.
Save lorennorman/1534990 to your computer and use it in GitHub Desktop.
learning me some openscad by playing with a hexagonal grid
module hexagon(radius)
{
circle(r=radius,$fn=6);
}
module shell(radius)
{
difference()
{
hexagon(radius*1.2); // base
hexagon(radius*1.1); // hole
}
}
module piece(radius)
{
translate([0, 0, -radius/12])
{
scale([1,1,0.5])
{
hexagon(radius);
}
}
}
module shell_with_piece(radius)
{
shell(radius);
piece(radius);
}
function column_to_offset(column, offset) = (column % 2) * offset;
module translate_to_hex(x_coord, y_coord, hex_width)
{
translate([x_coord*hex_width*1.75, y_coord*hex_width*2+column_to_offset(x_coord, hex_width), 0])
{
child(0);
}
}
module lattice(rows, columns, hex_width)
{
for(x = [0:columns-1])
{
for(y = [0:rows-1])
{
translate_to_hex(x, y, hex_width)
{
shell(hex_width);
}
}
}
}
linear_extrude(height=4)
{
lattice(4, 5, 8);
// translate_to_hex(2, 2, 4)
// {
// piece(4);
// }
}
@akshay22k
Copy link

Hey! I was wondering how I could edit this code to make stacks of hexagons at different sizes. I can make each individual layer but I'm not sure how to edit the code to add multiple layers. Any help would be appreciated. Cheers :)

@lorennorman
Copy link
Author

@knowledgewhale22 Great question! I don't know! This fragment is from a decade ago and I haven't tinkered with OpenScad since, however...

I would look at the translate function on line 36. You can see I'm passing a parameterized x and y value, but the z value is a constant 0, creating a 2 dimensional grid. I think if you want to stack them instead, you'll iterate while varying your radius as desired and increasing the z value to go "up".

Good luck!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment