Skip to content

Instantly share code, notes, and snippets.

@Kiwi
Forked from lorennorman/hex_grid.scad
Created July 5, 2022 15:51
Show Gist options
  • Save Kiwi/5cfc8ed64eeaa0c3ddf8d65446ef55e6 to your computer and use it in GitHub Desktop.
Save Kiwi/5cfc8ed64eeaa0c3ddf8d65446ef55e6 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);
// }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment