change grid2d to grid_copies for consistency

This commit is contained in:
Adrian Mariano 2022-10-17 19:47:09 -04:00
parent 30a7e40cf9
commit cbb47c5cd7
3 changed files with 41 additions and 33 deletions

View file

@ -293,7 +293,7 @@ module ycopies(spacing, n, l, sp)
// s = 20; // s = 20;
// s2 = s * sin(45); // s2 = s * sin(45);
// zcopies(s2,n=8) union() // 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); // sphere(d=s);
// Example: Hexagonal sphere packing // Example: Hexagonal sphere packing
// s = 20; // s = 20;
@ -301,7 +301,7 @@ module ycopies(spacing, n, l, sp)
// h = hyp_adj_to_opp(s,xyr); // h = hyp_adj_to_opp(s,xyr);
// zcopies(h,n=8) union() // zcopies(h,n=8) union()
// back(($idx%2)*xyr*cos(60)) // 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); // sphere(d=s);
// Example: // Example:
// zcopies([1,2,3,5,7]) sphere(d=1); // 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: // Description:
// Makes a square or hexagonal grid of copies of children, with an optional masking polygon or region. // Makes a square or hexagonal grid of copies of children, with an optional masking polygon or region.
// //
// Usage: // Usage:
// grid2d(spacing, size=, [stagger=], [scale=], [inside=]) CHILDREN; // grid_copies(spacing, size=, [stagger=], [scale=], [inside=]) CHILDREN;
// grid2d(n=, size=, [stagger=], [scale=], [inside=]) CHILDREN; // grid_copies(n=, size=, [stagger=], [scale=], [inside=]) CHILDREN;
// grid2d(spacing, [n], [stagger=], [scale=], [inside=]) CHILDREN; // grid_copies(spacing, [n], [stagger=], [scale=], [inside=]) CHILDREN;
// grid2d(n=, inside=, [stagger], [scale]) CHILDREN; // grid_copies(n=, inside=, [stagger], [scale]) CHILDREN;
// //
// Arguments: // Arguments:
// spacing = Distance between copies in [X,Y] or scalar distance. // 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. // `$row` is set to the integer row number for each child.
// //
// Examples: // Examples:
// grid2d(size=50, spacing=10) cylinder(d=10, h=1); // grid_copies(size=50, spacing=10) cylinder(d=10, h=1);
// grid2d(size=50, spacing=[10,15]) cylinder(d=10, h=1); // grid_copies(size=50, spacing=[10,15]) cylinder(d=10, h=1);
// grid2d(spacing=10, n=[13,7], stagger=true) cylinder(d=6, h=5); // grid_copies(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); // grid_copies(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, n=11, stagger=true) cylinder(d=5, h=1);
// //
// Example: // Example:
// poly = [[-25,-25], [25,25], [-25,25], [25,-25]]; // 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); // zrot(180/6) cylinder(d=5, h=1, $fn=6);
// %polygon(poly); // %polygon(poly);
// //
// Example: Using `$row` and `$col` // Example: Using `$row` and `$col`
// grid2d(spacing=8, n=8) // grid_copies(spacing=8, n=8)
// color(($row+$col)%2?"black":"red") // color(($row+$col)%2?"black":"red")
// cube([8,8,0.01], center=false); // 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 // // Makes a grid of hexagon pillars whose tops are all
// // angled to reflect light at [0,0,50], if they were shiny. // // angled to reflect light at [0,0,50], if they were shiny.
// hexregion = circle(r=50.01,$fn=6); // 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 // // Note: The union() is needed or else $pos will be
// // inexplicably unreadable. // // inexplicably unreadable.
// ref_v = (unit([0,0,50]-point3d($pos)) + UP)/2; // ref_v = (unit([0,0,50]-point3d($pos)) + UP)/2;
@ -384,7 +384,15 @@ module zcopies(spacing, n, l, sp)
// zrot(180/6) // zrot(180/6)
// cylinder(h=20, d=10/cos(180/6)+0.01, $fn=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) 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); req_children($children);
assert(in_list(stagger, [false, true, "alt"])); assert(in_list(stagger, [false, true, "alt"]));

View file

@ -13,7 +13,7 @@ Transforms | Related Distributors
`left()`, `right()` | `xcopies()` `left()`, `right()` | `xcopies()`
`fwd()`, `back()` | `ycopies()` `fwd()`, `back()` | `ycopies()`
`down()`, `up()` | `zcopies()` `down()`, `up()` | `zcopies()`
`move()`, `translate()` | `move_copies()`, `line_of()`, `grid2d()` `move()`, `translate()` | `move_copies()`, `line_of()`, `grid_copies()`
`xrot()` | `xrot_copies()` `xrot()` | `xrot_copies()`
`yrot()` | `yrot_copies()` `yrot()` | `yrot_copies()`
`zrot()` | `zrot_copies()` `zrot()` | `zrot_copies()`
@ -127,30 +127,30 @@ line_of(p1=[0,100,0], p2=[100,0,0], n=4)
sphere(d=10); 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: axes at the same time:
```openscad-2D ```openscad-2D
include <BOSL2/std.scad> include <BOSL2/std.scad>
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 spacing can be separately specified for both the X and Y axes, as can
the count of rows and columns: the count of rows and columns:
```openscad-2D ```openscad-2D
include <BOSL2/std.scad> include <BOSL2/std.scad>
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 ```openscad-2D
include <BOSL2/std.scad> include <BOSL2/std.scad>
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"`: You can get the alternate stagger pattern if you set `stagger="alt"`:
```openscad-2D ```openscad-2D
include <BOSL2/std.scad> include <BOSL2/std.scad>
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 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. then that will force the X and Y spacings between columns and rows instead.
```openscad-2D ```openscad-2D
include <BOSL2/std.scad> include <BOSL2/std.scad>
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: You can alternately specify a grid using size and spacing:
```openscad-2D ```openscad-2D
include <BOSL2/std.scad> include <BOSL2/std.scad>
grid2d(20, size=100) sphere(d=10); grid_copies(20, size=100) sphere(d=10);
``` ```
```openscad-2D ```openscad-2D
include <BOSL2/std.scad> include <BOSL2/std.scad>
grid2d(20, size=[100,80]) sphere(d=10); grid_copies(20, size=[100,80]) sphere(d=10);
``` ```
```openscad-2D ```openscad-2D
include <BOSL2/std.scad> include <BOSL2/std.scad>
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: You can also make grids by specifying size and column/row count:
```openscad-2D ```openscad-2D
include <BOSL2/std.scad> include <BOSL2/std.scad>
grid2d(n=5, size=100) sphere(d=10); grid_copies(n=5, size=100) sphere(d=10);
``` ```
```openscad-2D ```openscad-2D
include <BOSL2/std.scad> include <BOSL2/std.scad>
grid2d(n=[4,5], size=100) sphere(d=10); grid_copies(n=[4,5], size=100) sphere(d=10);
``` ```
```openscad-2D ```openscad-2D
include <BOSL2/std.scad> include <BOSL2/std.scad>
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 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 the polygon or region will be created. To fill a star shape with items, you
can do something like: can do something like:
```openscad-3D ```openscad-3D
include <BOSL2/std.scad> include <BOSL2/std.scad>
poly = [for (i=[0:11]) polar_to_xy(50*(i%2+1), i*360/12-90)]; 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); cylinder(d=4,h=10,spin=90,$fn=6);
} }
``` ```

View file

@ -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 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 ```openscad-3D
include <BOSL2/std.scad> include <BOSL2/std.scad>
@ -546,7 +546,7 @@ rgn = [
]; ];
difference() { difference() {
cyl(h=5, d=120); 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);
} }
``` ```