From cbb47c5cd75e200cf12c68b272a5f2638a8f5acc Mon Sep 17 00:00:00 2001 From: Adrian Mariano Date: Mon, 17 Oct 2022 19:47:09 -0400 Subject: [PATCH] change grid2d to grid_copies for consistency --- distributors.scad | 38 +++++++++++++++++++++++--------------- tutorials/Distributors.md | 32 ++++++++++++++++---------------- tutorials/Paths.md | 4 ++-- 3 files changed, 41 insertions(+), 33 deletions(-) diff --git a/distributors.scad b/distributors.scad index e0e686d..a0ce96f 100644 --- a/distributors.scad +++ b/distributors.scad @@ -293,7 +293,7 @@ module ycopies(spacing, n, l, sp) // s = 20; // s2 = s * sin(45); // zcopies(s2,n=8) union() -// grid2d([s2,s2],n=8,stagger=($idx%2)? true : "alt") +// grid_copies([s2,s2],n=8,stagger=($idx%2)? true : "alt") // sphere(d=s); // Example: Hexagonal sphere packing // s = 20; @@ -301,7 +301,7 @@ module ycopies(spacing, n, l, sp) // h = hyp_adj_to_opp(s,xyr); // zcopies(h,n=8) union() // back(($idx%2)*xyr*cos(60)) -// grid2d(s,n=[12,7],stagger=($idx%2)? "alt" : true) +// grid_copies(s,n=[12,7],stagger=($idx%2)? "alt" : true) // sphere(d=s); // Example: // zcopies([1,2,3,5,7]) sphere(d=1); @@ -329,16 +329,16 @@ module zcopies(spacing, n, l, sp) -// Module: grid2d() +// Module: grid_copies() // // Description: // Makes a square or hexagonal grid of copies of children, with an optional masking polygon or region. // // Usage: -// grid2d(spacing, size=, [stagger=], [scale=], [inside=]) CHILDREN; -// grid2d(n=, size=, [stagger=], [scale=], [inside=]) CHILDREN; -// grid2d(spacing, [n], [stagger=], [scale=], [inside=]) CHILDREN; -// grid2d(n=, inside=, [stagger], [scale]) CHILDREN; +// grid_copies(spacing, size=, [stagger=], [scale=], [inside=]) CHILDREN; +// grid_copies(n=, size=, [stagger=], [scale=], [inside=]) CHILDREN; +// grid_copies(spacing, [n], [stagger=], [scale=], [inside=]) CHILDREN; +// grid_copies(n=, inside=, [stagger], [scale]) CHILDREN; // // Arguments: // spacing = Distance between copies in [X,Y] or scalar distance. @@ -355,20 +355,20 @@ module zcopies(spacing, n, l, sp) // `$row` is set to the integer row number for each child. // // Examples: -// grid2d(size=50, spacing=10) cylinder(d=10, h=1); -// grid2d(size=50, spacing=[10,15]) cylinder(d=10, h=1); -// grid2d(spacing=10, n=[13,7], stagger=true) cylinder(d=6, h=5); -// grid2d(spacing=10, n=[13,7], stagger="alt") cylinder(d=6, h=5); -// grid2d(size=50, n=11, stagger=true) cylinder(d=5, h=1); +// grid_copies(size=50, spacing=10) cylinder(d=10, h=1); +// grid_copies(size=50, spacing=[10,15]) cylinder(d=10, h=1); +// grid_copies(spacing=10, n=[13,7], stagger=true) cylinder(d=6, h=5); +// grid_copies(spacing=10, n=[13,7], stagger="alt") cylinder(d=6, h=5); +// grid_copies(size=50, n=11, stagger=true) cylinder(d=5, h=1); // // Example: // poly = [[-25,-25], [25,25], [-25,25], [25,-25]]; -// grid2d(spacing=5, stagger=true, inside=poly) +// grid_copies(spacing=5, stagger=true, inside=poly) // zrot(180/6) cylinder(d=5, h=1, $fn=6); // %polygon(poly); // // Example: Using `$row` and `$col` -// grid2d(spacing=8, n=8) +// grid_copies(spacing=8, n=8) // color(($row+$col)%2?"black":"red") // cube([8,8,0.01], center=false); // @@ -376,7 +376,7 @@ module zcopies(spacing, n, l, sp) // // Makes a grid of hexagon pillars whose tops are all // // angled to reflect light at [0,0,50], if they were shiny. // hexregion = circle(r=50.01,$fn=6); -// grid2d(spacing=10, stagger=true, inside=hexregion) union() { +// grid_copies(spacing=10, stagger=true, inside=hexregion) union() { // // Note: The union() is needed or else $pos will be // // inexplicably unreadable. // ref_v = (unit([0,0,50]-point3d($pos)) + UP)/2; @@ -384,7 +384,15 @@ module zcopies(spacing, n, l, sp) // zrot(180/6) // cylinder(h=20, d=10/cos(180/6)+0.01, $fn=6); // } + +function grid_copies(spacing, n, size, stagger=false, inside=undef, nonzero) = no_function("grid_copies"); module grid2d(spacing, n, size, stagger=false, inside=undef, nonzero) +{ + deprecate("grid_copies"); + grid_copies(spacing, n, size, stagger, inside, nonzero) children(); +} + +module grid_copies(spacing, n, size, stagger=false, inside=undef, nonzero) { req_children($children); assert(in_list(stagger, [false, true, "alt"])); diff --git a/tutorials/Distributors.md b/tutorials/Distributors.md index 2d06b40..98cd29b 100644 --- a/tutorials/Distributors.md +++ b/tutorials/Distributors.md @@ -13,7 +13,7 @@ Transforms | Related Distributors `left()`, `right()` | `xcopies()` `fwd()`, `back()` | `ycopies()` `down()`, `up()` | `zcopies()` -`move()`, `translate()` | `move_copies()`, `line_of()`, `grid2d()` +`move()`, `translate()` | `move_copies()`, `line_of()`, `grid_copies()` `xrot()` | `xrot_copies()` `yrot()` | `yrot_copies()` `zrot()` | `zrot_copies()` @@ -127,30 +127,30 @@ line_of(p1=[0,100,0], p2=[100,0,0], n=4) sphere(d=10); ``` -The `grid2d()` command will let you spread copies across both the X and Y +The `grid_copies()` command will let you spread copies across both the X and Y axes at the same time: ```openscad-2D include -grid2d(20, n=6) sphere(d=10); +grid_copies(20, n=6) sphere(d=10); ``` The spacing can be separately specified for both the X and Y axes, as can the count of rows and columns: ```openscad-2D include -grid2d([20,30], n=[6,4]) sphere(d=10); +grid_copies([20,30], n=[6,4]) sphere(d=10); ``` -Another neat trick of `grid2d()`, is that you can stagger the output: +Another neat trick of `grid_copies()`, is that you can stagger the output: ```openscad-2D include -grid2d(20, n=[12,6], stagger=true) sphere(d=10); +grid_copies(20, n=[12,6], stagger=true) sphere(d=10); ``` You can get the alternate stagger pattern if you set `stagger="alt"`: ```openscad-2D include -grid2d(20, n=[12,6], stagger="alt") sphere(d=10); +grid_copies(20, n=[12,6], stagger="alt") sphere(d=10); ``` By default, if you give a scalar for the spacing value, staggering will give @@ -159,49 +159,49 @@ six of the surrounding items. If you give the spacing as a 2-item vector, then that will force the X and Y spacings between columns and rows instead. ```openscad-2D include -grid2d([20,20], n=6, stagger=true) sphere(d=10); +grid_copies([20,20], n=6, stagger=true) sphere(d=10); ``` You can alternately specify a grid using size and spacing: ```openscad-2D include -grid2d(20, size=100) sphere(d=10); +grid_copies(20, size=100) sphere(d=10); ``` ```openscad-2D include -grid2d(20, size=[100,80]) sphere(d=10); +grid_copies(20, size=[100,80]) sphere(d=10); ``` ```openscad-2D include -grid2d(20, size=[100,80], stagger=true) sphere(d=10); +grid_copies(20, size=[100,80], stagger=true) sphere(d=10); ``` You can also make grids by specifying size and column/row count: ```openscad-2D include -grid2d(n=5, size=100) sphere(d=10); +grid_copies(n=5, size=100) sphere(d=10); ``` ```openscad-2D include -grid2d(n=[4,5], size=100) sphere(d=10); +grid_copies(n=[4,5], size=100) sphere(d=10); ``` ```openscad-2D include -grid2d(n=[4,5], size=[100,80]) sphere(d=10); +grid_copies(n=[4,5], size=[100,80]) sphere(d=10); ``` -Finally, the `grid2d()` command will let you give a polygon or region shape +Finally, the `grid_copies()` command will let you give a polygon or region shape to fill with items. Only the items in the grid whose center would be inside the polygon or region will be created. To fill a star shape with items, you can do something like: ```openscad-3D include poly = [for (i=[0:11]) polar_to_xy(50*(i%2+1), i*360/12-90)]; -grid2d(5, stagger=true, inside=poly) { +grid_copies(5, stagger=true, inside=poly) { cylinder(d=4,h=10,spin=90,$fn=6); } ``` diff --git a/tutorials/Paths.md b/tutorials/Paths.md index aa58a75..7ef3e0f 100644 --- a/tutorials/Paths.md +++ b/tutorials/Paths.md @@ -536,7 +536,7 @@ region(rgn); ``` You can use regions for several useful things. If you wanted a grid of holes in your object that -form the shape given by a region, you can do that with `grid2d()`: +form the shape given by a region, you can do that with `grid_copies()`: ```openscad-3D include @@ -546,7 +546,7 @@ rgn = [ ]; difference() { cyl(h=5, d=120); - grid2d(size=[120,120], spacing=[4,4], inside=rgn) cyl(h=10,d=2); + grid_copies(size=[120,120], spacing=[4,4], inside=rgn) cyl(h=10,d=2); } ```