chiark / gitweb /
knifeblock: Holes refactor: break out HexGrid (nfc)
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Thu, 1 Jan 2015 23:53:19 +0000 (23:53 +0000)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Thu, 1 Jan 2015 23:53:19 +0000 (23:53 +0000)
knifeblock.scad

index b1a4052f15383261b5bc6437b598dde32a8d03b1..4742458f08b5bfd4776b33b6d11c0d0239241626 100644 (file)
@@ -224,6 +224,20 @@ module HolesScope(){
   }
 }
 
+module HexGrid(imin,imax,jmin,jmax) {
+  for (i=[imin:imax]) {
+    for (j=[jmin:jmax]) {
+      translate([j * sqrt(3) * holepitch,
+                (i+0.5)*holepitch,
+                0]) {
+       child();
+       translate([sqrt(3)/2 * holepitch, -0.5 * holepitch, 0])
+         child();
+      }
+    }
+  }
+}
+
 module Hole(){
   cylinder(r=holesize/2, h=40, $fn=40);
 }
@@ -234,18 +248,9 @@ module Holes(){
   jmin = ceil((maxx-minx)/(sqrt(3)*holepitch));
   echo("Holes X count 2 x", jmin);
   intersection(){
-    translate([holeoffx * holepitch, holeoffy * holepitch, 0]) {
-      for (i=[0:imax]) {
-       translate([0, (i+0.5)*holepitch, -20])
-         for (j=[-jmin:2]) {
-           translate([j * sqrt(3) * holepitch, 0, 0]) {
-             Hole();
-             translate([sqrt(3)/2 * holepitch, -0.5 * holepitch, 0])
-               Hole();
-           }
-         }
-      }
-    }
+    translate([holeoffx * holepitch, holeoffy * holepitch, -20])
+      HexGrid(0,imax,-jmin,2)
+      Hole();
     HolesScope();
   }
 }