Skip to content

Instantly share code, notes, and snippets.

@JustinSDK
Last active April 11, 2017 12:24
Show Gist options
  • Save JustinSDK/6ca02fe8da242c83156e8ac51a1c8d4d to your computer and use it in GitHub Desktop.
Save JustinSDK/6ca02fe8da242c83156e8ac51a1c8d4d to your computer and use it in GitHub Desktop.
//radius determines the size of the hexagon
radius = 20;
levels = 15;
spacing = 2;
thickness = 20;
module hexagons(radius, spacing, levels) {
beginning_n = 2 * levels - 1;
offset_x = radius * cos(30);
offset_y = radius + radius * sin(30);
module hexagon() {
rotate(30)
offset(r = -spacing / 2)
circle(radius, $fn = 6);
}
module line_hexagons(n) {
offset = 2 * offset_x;
for(i = [0:n - 1]) {
offset_p = [i * offset, 0, 0];
translate(offset_p)
hexagon();
}
}
translate([2 * (offset_x - offset_x * levels) , 0, 0])
union() {
line_hexagons(beginning_n);
if(levels > 1) {
for(i = [1:beginning_n - (levels)]) {
translate([offset_x * i, offset_y * i, 0])
line_hexagons(beginning_n - i);
mirror([0, 1, 0])
translate([offset_x * i, offset_y * i, 0])
line_hexagons(beginning_n - i);
}
}
}
}
linear_extrude(thickness)
hexagons(radius, spacing, levels);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment