1
0
mirror of https://github.com/JustinSDK/dotSCAD.git synced 2025-08-15 11:14:17 +02:00

return cells

This commit is contained in:
Justin Lin
2020-03-30 15:34:24 +08:00
parent a2a68f11af
commit 12a31042f3
3 changed files with 26 additions and 20 deletions

View File

@@ -18,11 +18,15 @@ function _neighbors(fcord, seed, cell_w) = [
nbr nbr
]; ];
function _nz_worley3_classic(p, nbrs, dist) = function _nz_worley3_classic(p, nbrs, dist) =
min([ let(
for(nbr = nbrs) cells = [
_distance(nbr, p, dist) for(nbr = nbrs)
]); [nbr[0], nbr[1], nbr[2], _distance(nbr, p, dist)]
],
sorted = sort(cells, by = "idx", idx = 3)
)
sorted[0];
function _nz_worley3_border(p, nbrs, dist) = function _nz_worley3_border(p, nbrs, dist) =
let( let(
@@ -35,7 +39,7 @@ function _nz_worley3_border(p, nbrs, dist) =
b = [sorted[1][0], sorted[1][1], sorted[1][2]], b = [sorted[1][0], sorted[1][1], sorted[1][2]],
m = (a + b) / 2 m = (a + b) / 2
) )
(p - m) * (a - m); [a[0], a[1], a[2], (p - m) * (a - m)];
function _nz_worley3(p, seed, cell_w, dist) = function _nz_worley3(p, seed, cell_w, dist) =
let( let(

View File

@@ -1,21 +1,23 @@
use <experimental/nz_worley3.scad>; use <experimental/nz_worley3.scad>;
size = [20, 20, 20]; size = [20, 20, 20];
cell_w = 5; cell_w = 10;
dist = "euclidean"; // [euclidean, manhattan, chebyshev, border] dist = "euclidean"; // [euclidean, manhattan, chebyshev, border]
seed = 5; seed = 51;
points = [ points = [
for(z = [0:size[2] - 1]) for(z = [0:size[2] - 1])
for(y = [0:size[1] - 1]) for(y = [0:size[1] - 1])
for(x = [0:size[0] - 1]) for(x = [0:size[0] - 1])
[x, y, z, nz_worley3(x, y, z, seed, cell_w, dist)] [x, y, z]
]; ];
max_dist = max([for(p = points) p[3]]); cells = [for(p = points) nz_worley3(p[0], p[1], p[2], seed, cell_w, dist)];
for(p = points) {
c = p[3] / max_dist; max_dist = max([for(c = cells) c[3]]);
for(i = [0:len(cells) - 1]) {
c = cells[i][3] / max_dist;
color([c, c, c, c]) color([c, c, c, c])
translate([p[0], p[1], p[2]]) translate(points[i])
cube(1); cube(1);
} }

View File

@@ -1,9 +1,10 @@
use <experimental/nz_worley3s.scad>; use <experimental/nz_worley3s.scad>;
use <util/dedup.scad>;
size = [20, 20, 20]; size = [20, 20, 20];
cell_w = 5; cell_w = 10;
dist = "euclidean"; // [euclidean, manhattan, chebyshev, border] dist = "euclidean"; // [euclidean, manhattan, chebyshev, border]
seed = 5; seed = 51;
points = [ points = [
for(z = [0:size[2] - 1]) for(z = [0:size[2] - 1])
@@ -11,13 +12,12 @@ points = [
for(x = [0:size[0] - 1]) for(x = [0:size[0] - 1])
[x, y, z] [x, y, z]
]; ];
noises = nz_worley3s(points, seed, cell_w, dist);
max_dist = max(noises); cells = nz_worley3s(points, seed, cell_w, dist);
for(i = [0:len(noises) - 1]) { max_dist = max([for(c = cells) c[3]]);
c = noises[i] / max_dist; for(i = [0:len(cells) - 1]) {
c = cells[i][3] / max_dist;
color([c, c, c, c]) color([c, c, c, c])
translate(points[i]) translate(points[i])
cube(1); cube(1);