diff --git a/README.md b/README.md index 8768c229..89c4012d 100644 --- a/README.md +++ b/README.md @@ -196,10 +196,10 @@ See [examples](examples). - [noise/nz_perlin2s](https://openhome.cc/eGossip/OpenSCAD/lib2x-nz_perlin2s.html) - [noise/nz_perlin3](https://openhome.cc/eGossip/OpenSCAD/lib2x-nz_perlin3.html) - [noise/nz_perlin3s](https://openhome.cc/eGossip/OpenSCAD/lib2x-nz_perlin3s.html) -- noise/nz_worley1 -- noise/nz_worley1s -- noise/nz_worley2 +- [noise/nz_worley2](https://openhome.cc/eGossip/OpenSCAD/lib2x-nz_worley2.html) - noise/nz_worley2s +- noise/nz_worley3 +- noise/nz_worley3s - noise/nz_cell ## Bugs and Feedback diff --git a/docs/images/lib2x-nz_worley2-1.JPG b/docs/images/lib2x-nz_worley2-1.JPG new file mode 100644 index 00000000..49ba1a81 Binary files /dev/null and b/docs/images/lib2x-nz_worley2-1.JPG differ diff --git a/docs/images/lib2x-nz_worley2-2.JPG b/docs/images/lib2x-nz_worley2-2.JPG new file mode 100644 index 00000000..f7722a7b Binary files /dev/null and b/docs/images/lib2x-nz_worley2-2.JPG differ diff --git a/docs/lib2x-nz_worley2.md b/docs/lib2x-nz_worley2.md new file mode 100644 index 00000000..9f51d7b5 --- /dev/null +++ b/docs/lib2x-nz_worley2.md @@ -0,0 +1,53 @@ +# nz_worley2 + +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. + +![nz_worley2](images/lib2x-nz_worley2-1.JPG) + +**Since:** 2.3 + +## Parameters + +- `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. +- `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 + + use ; + use ; + + size = [100, 50]; + tile_w = 10; + dist = "euclidean"; // [euclidean, manhattan, chebyshev, border] + seed = 51; + + points = [ + for(y = [0:size[1] - 1]) + for(x = [0:size[0] - 1]) + [x, y] + ]; + + cells = [for(p = points) nz_worley2(p[0], p[1], seed, tile_w, dist)]; + + max_dist = max([for(c = cells) c[2]]); + for(i = [0:len(cells) - 1]) { + c = cells[i][2] / max_dist; + color([c, c, c]) + linear_extrude(cells[i][2]) + translate(points[i]) + square(1); + } + + cells_pts = dedup([for(c = cells) [c[0], c[1]]]); + for(p = cells_pts) { + translate(p) + linear_extrude(max_dist) + square(1); + } + +![nz_worley2](images/lib2x-nz_worley2-2.JPG) \ No newline at end of file diff --git a/src/noise/nz_worley2.scad b/src/noise/nz_worley2.scad index f2449850..d785fabc 100644 --- a/src/noise/nz_worley2.scad +++ b/src/noise/nz_worley2.scad @@ -1,3 +1,13 @@ +/** +* nz_worley2.scad +* +* @copyright Justin Lin, 2020 +* @license https://opensource.org/licenses/lgpl-3.0.html +* +* @see https://openhome.cc/eGossip/OpenSCAD/lib2x-nz_worley2.html +* +**/ + use ; use ;