diff --git a/docs/lib2x-nz_worley2.md b/docs/lib2x-nz_worley2.md index 9f51d7b5..e1649036 100644 --- a/docs/lib2x-nz_worley2.md +++ b/docs/lib2x-nz_worley2.md @@ -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 ; 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]) { diff --git a/docs/lib2x-nz_worley2s.md b/docs/lib2x-nz_worley2s.md index fd2b0262..690cd2b0 100644 --- a/docs/lib2x-nz_worley2s.md +++ b/docs/lib2x-nz_worley2s.md @@ -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 ; 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; diff --git a/src/noise/_impl/_nz_worley2_impl.scad b/src/noise/_impl/_nz_worley2_impl.scad index 8fd8b217..4b3b6d09 100644 --- a/src/noise/_impl/_nz_worley2_impl.scad +++ b/src/noise/_impl/_nz_worley2_impl.scad @@ -1,16 +1,16 @@ use ; use ; -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); \ No newline at end of file diff --git a/src/noise/_impl/_nz_worley3_impl.scad b/src/noise/_impl/_nz_worley3_impl.scad index 5c69b215..744ce7ba 100644 --- a/src/noise/_impl/_nz_worley3_impl.scad +++ b/src/noise/_impl/_nz_worley3_impl.scad @@ -1,7 +1,7 @@ use ; use ; -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); \ No newline at end of file diff --git a/src/noise/nz_worley2.scad b/src/noise/nz_worley2.scad index d785fabc..bf0478b1 100644 --- a/src/noise/nz_worley2.scad +++ b/src/noise/nz_worley2.scad @@ -11,6 +11,6 @@ use ; use ; -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); \ No newline at end of file + _nz_worley2([x, y], sd, grid_w, dist); \ No newline at end of file diff --git a/src/noise/nz_worley2s.scad b/src/noise/nz_worley2s.scad index 1e2ca349..f40f2162 100644 --- a/src/noise/nz_worley2s.scad +++ b/src/noise/nz_worley2s.scad @@ -11,6 +11,6 @@ use ; use ; -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)]; \ No newline at end of file + [for(p = points) _nz_worley2(p, sd, grid_w, dist)]; \ No newline at end of file