1
0
mirror of https://github.com/JustinSDK/dotSCAD.git synced 2025-08-12 17:54:18 +02:00

rename param

This commit is contained in:
Justin Lin
2020-04-07 17:34:27 +08:00
parent 12ece2deef
commit cc1e381fd8
6 changed files with 24 additions and 24 deletions

View File

@@ -2,7 +2,7 @@
Returns the 2D [Worley noise](https://en.wikipedia.org/wiki/Worley_noise) value `[cell_x, cell_y, noise]` at the (x, y) coordinate.
It divides the space into tiles. The nucleus of each cell is randomly placed in a tile.
It divides the space into grids. The nucleus of each cell is randomly placed in a grid.
![nz_worley2](images/lib2x-nz_worley2-1.JPG)
@@ -13,7 +13,7 @@ It divides the space into tiles. The nucleus of each cell is randomly placed in
- `x` : The x coordinate.
- `y` : The y coordinate.
- `seed` : The random seed.
- `tile_w` : The tile width. Default to 10. Smaller `tile_w` makes more cells.
- `grid_w` : The grid width. Default to 10. Smaller `grid_w` makes more cells.
- `dist` : The noise value of each point is based on its distance to other cells. Different distance strategies make different noises. The `dist` parameter accepts `"euclidean"`, `"manhattan"`, `"chebyshev"` or `"border"`.
## Examples
@@ -22,7 +22,7 @@ It divides the space into tiles. The nucleus of each cell is randomly placed in
use <util/dedup.scad>;
size = [100, 50];
tile_w = 10;
grid_w = 10;
dist = "euclidean"; // [euclidean, manhattan, chebyshev, border]
seed = 51;
@@ -32,7 +32,7 @@ It divides the space into tiles. The nucleus of each cell is randomly placed in
[x, y]
];
cells = [for(p = points) nz_worley2(p[0], p[1], seed, tile_w, dist)];
cells = [for(p = points) nz_worley2(p[0], p[1], seed, grid_w, dist)];
max_dist = max([for(c = cells) c[2]]);
for(i = [0:len(cells) - 1]) {

View File

@@ -2,7 +2,7 @@
Returns 2D [Worley noise](https://en.wikipedia.org/wiki/Worley_noise) values `[cell_x, cell_y, noise]` at (x, y) coordinates.
It divides the space into tiles. The nucleus of each cell is randomly placed in a tile.
It divides the space into grids. The nucleus of each cell is randomly placed in a grid.
![nz_worley2s](images/lib2x-nz_worley2s-1.JPG)
@@ -12,7 +12,7 @@ It divides the space into tiles. The nucleus of each cell is randomly placed in
- `points` : A list of `[x, y]` coordinates.
- `seed` : The random seed. If it's ignored, a randomized value will be used.
- `tile_w` : The tile width. Default to 10. Smaller `tile_w` makes more cells.
- `grid_w` : The grid width. Default to 10. Smaller `grid_w` makes more cells.
- `dist` : The noise value of each point is based on its distance to other cells. Different distance strategies make different noises. The `dist` parameter accepts `"euclidean"`, `"manhattan"`, `"chebyshev"` or `"border"`.
## Examples
@@ -20,7 +20,7 @@ It divides the space into tiles. The nucleus of each cell is randomly placed in
use <noise/nz_worley2s.scad>;
size = [100, 50];
tile_w = 10;
grid_w = 10;
dist = "euclidean"; // [euclidean, manhattan, chebyshev, border]
seed = 51;
@@ -30,7 +30,7 @@ It divides the space into tiles. The nucleus of each cell is randomly placed in
[x, y]
];
cells = nz_worley2s(points, seed, tile_w, dist);
cells = nz_worley2s(points, seed, grid_w, dist);
for(i = [0:len(cells) - 1]) {
h = norm([cells[i][0], cells[i][1]]) % 10;

View File

@@ -1,16 +1,16 @@
use <noise/_impl/_nz_worley_comm.scad>;
use <util/sort.scad>;
function _neighbors(fcord, seed, tile_w) = [
function _neighbors(fcord, seed, grid_w) = [
for(y = [-1:1])
for(x = [-1:1])
let(
nx = fcord[0] + x,
ny = fcord[1] + y,
sd_base = abs(nx + ny * tile_w),
sd_base = abs(nx + ny * grid_w),
sd1 = _lookup_noise_table(seed + sd_base),
sd2 = _lookup_noise_table(sd1 * 255 + sd_base),
nbr = [(nx + sd1) * tile_w, (ny + sd2) * tile_w]
nbr = [(nx + sd1) * grid_w, (ny + sd2) * grid_w]
)
nbr
];
@@ -38,10 +38,10 @@ function _nz_worley2_border(p, nbrs) =
)
[a[0], a[1], (p - m) * (a - m)];
function _nz_worley2(p, seed, tile_w, dist) =
function _nz_worley2(p, seed, grid_w, dist) =
let(
fcord = [floor(p[0] / tile_w), floor(p[1] / tile_w)],
nbrs = _neighbors(fcord, seed, tile_w)
fcord = [floor(p[0] / grid_w), floor(p[1] / grid_w)],
nbrs = _neighbors(fcord, seed, grid_w)
)
dist == "border" ? _nz_worley2_border(p, nbrs) :
_nz_worley2_classic(p, nbrs, dist);

View File

@@ -1,7 +1,7 @@
use <noise/_impl/_nz_worley_comm.scad>;
use <util/sort.scad>;
function _neighbors(fcord, seed, tile_w) = [
function _neighbors(fcord, seed, grid_w) = [
for(z = [-1:1])
for(y = [-1:1])
for(x = [-1:1])
@@ -9,11 +9,11 @@ function _neighbors(fcord, seed, tile_w) = [
nx = fcord[0] + x,
ny = fcord[1] + y,
nz = fcord[2] + z,
sd_base = abs(nx + ny * tile_w + nz * tile_w * tile_w),
sd_base = abs(nx + ny * grid_w + nz * grid_w * grid_w),
sd1 = _lookup_noise_table(seed + sd_base),
sd2 = _lookup_noise_table(sd1 * 255 + sd_base),
sd3 = _lookup_noise_table(sd2 * 255 + sd_base),
nbr = [(nx + sd1) * tile_w, (ny + sd2) * tile_w, (nz + sd3) * tile_w]
nbr = [(nx + sd1) * grid_w, (ny + sd2) * grid_w, (nz + sd3) * grid_w]
)
nbr
];
@@ -41,10 +41,10 @@ function _nz_worley3_border(p, nbrs) =
)
[a[0], a[1], a[2], (p - m) * (a - m)];
function _nz_worley3(p, seed, tile_w, dist) =
function _nz_worley3(p, seed, grid_w, dist) =
let(
fcord = [floor(p[0] / tile_w), floor(p[1] / tile_w), floor(p[2] / tile_w)],
nbrs = _neighbors(fcord, seed, tile_w)
fcord = [floor(p[0] / grid_w), floor(p[1] / grid_w), floor(p[2] / grid_w)],
nbrs = _neighbors(fcord, seed, grid_w)
)
dist == "border" ? _nz_worley3_border(p, nbrs) :
_nz_worley3_classic(p, nbrs, dist);

View File

@@ -11,6 +11,6 @@
use <util/rand.scad>;
use <noise/_impl/_nz_worley2_impl.scad>;
function nz_worley2(x, y, seed, tile_w = 10, dist = "euclidean") =
function nz_worley2(x, y, seed, grid_w = 10, dist = "euclidean") =
let(sd = is_undef(seed) ? floor(rand(0, 256)) : seed % 256)
_nz_worley2([x, y], sd, tile_w, dist);
_nz_worley2([x, y], sd, grid_w, dist);

View File

@@ -11,6 +11,6 @@
use <util/rand.scad>;
use <noise/_impl/_nz_worley2_impl.scad>;
function nz_worley2s(points, seed, tile_w = 10, dist = "euclidean") =
function nz_worley2s(points, seed, grid_w = 10, dist = "euclidean") =
let(sd = is_undef(seed) ? floor(rand(0, 256)) : seed % 256)
[for(p = points) _nz_worley2(p, sd, tile_w, dist)];
[for(p = points) _nz_worley2(p, sd, grid_w, dist)];