diff --git a/README.md b/README.md index 144443ab..295ec250 100644 --- a/README.md +++ b/README.md @@ -200,7 +200,7 @@ See [examples](examples). - [noise/nz_worley2s](https://openhome.cc/eGossip/OpenSCAD/lib2x-nz_worley2s.html) - [noise/nz_worley3](https://openhome.cc/eGossip/OpenSCAD/lib2x-nz_worley3.html) - [noise/nz_worley3s](https://openhome.cc/eGossip/OpenSCAD/lib2x-nz_worley3s.html) -- noise/nz_cell +- [noise/nz_cell](https://openhome.cc/eGossip/OpenSCAD/lib2x-nz_cell.html) ## Bugs and Feedback diff --git a/docs/images/lib2x-nz_cell-1.JPG b/docs/images/lib2x-nz_cell-1.JPG new file mode 100644 index 00000000..6d33c6c5 Binary files /dev/null and b/docs/images/lib2x-nz_cell-1.JPG differ diff --git a/docs/images/lib2x-nz_cell-2.JPG b/docs/images/lib2x-nz_cell-2.JPG new file mode 100644 index 00000000..2111b0ba Binary files /dev/null and b/docs/images/lib2x-nz_cell-2.JPG differ diff --git a/docs/lib2x-nz_cell.md b/docs/lib2x-nz_cell.md new file mode 100644 index 00000000..0d395b93 --- /dev/null +++ b/docs/lib2x-nz_cell.md @@ -0,0 +1,48 @@ +# nz_cell + +It's an implementation of [Worley noise](https://en.wikipedia.org/wiki/Worley_noise). The feature points can be customized. The function returns `[cell_x, cell_y(, cell_z), noise]` value at the (x, y(,z)) coordinate. + +**Since:** 2.3 + +## Parameters +points, p, dist +- `points` : The feature points, can be 2D or 3D. +- `p` : The pixel or voxel coordinate. +- `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]; + half_size = size / 2; + + pts_angles = golden_spiral( + from = 3, + to = 10, + point_distance = 3 + ); + + feature_points = [for(pt_angle = pts_angles) pt_angle[0] + half_size]; + noised = [ + for(y = [0:size[1] - 1]) + for(x = [0:size[0] - 1]) + [x, y, nz_cell(feature_points, [x, y])] + ]; + + max_dist = max([for(n = noised) n[2]]); + + for(n = noised) { + c = abs(n[2] / max_dist); + color([c, c, c]) + linear_extrude(n[2] + 0.1) + translate([n[0], n[1]]) + square(1); + } + +![nz_cell](images/lib2x-nz_cell-1.JPG) + +You can build a model such as: + +![nz_cell](images/lib2x-nz_cell-2.JPG) \ No newline at end of file diff --git a/src/experimental/demo/nz_cell_demo.scad b/src/experimental/demo/nz_cell_demo.scad deleted file mode 100644 index 3a3bfb1b..00000000 --- a/src/experimental/demo/nz_cell_demo.scad +++ /dev/null @@ -1,28 +0,0 @@ -use ; -use ; - -size = [100, 50]; -half_size = size / 2; - -pts_angles = golden_spiral( - from = 3, - to = 10, - point_distance = 3 -); - -feature_points = [for(pt_angle = pts_angles) pt_angle[0] + half_size]; -noised = [ - for(y = [0:size[1] - 1]) - for(x = [0:size[0] - 1]) - [x, y, nz_cell(feature_points, [x, y])] -]; - -max_dist = max([for(n = noised) n[2]]); - -for(n = noised) { - c = abs(n[2] / max_dist); - color([c, c, c]) - linear_extrude(n[2] + 0.1) - translate([n[0], n[1]]) - square(1); -} \ No newline at end of file diff --git a/src/noise/nz_cell.scad b/src/noise/nz_cell.scad index b6f18a12..82693e61 100644 --- a/src/noise/nz_cell.scad +++ b/src/noise/nz_cell.scad @@ -1,3 +1,13 @@ +/** +* nz_cell.scad +* +* @copyright Justin Lin, 2020 +* @license https://opensource.org/licenses/lgpl-3.0.html +* +* @see https://openhome.cc/eGossip/OpenSCAD/lib2x-nz_cell.html +* +**/ + use ; function nz_cell(points, p, dist = "euclidean") =