1
0
mirror of https://github.com/JustinSDK/dotSCAD.git synced 2025-03-14 11:10:01 +01: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
];
function _nz_worley3_classic(p, nbrs, dist) =
min([
for(nbr = nbrs)
_distance(nbr, p, dist)
]);
function _nz_worley3_classic(p, nbrs, dist) =
let(
cells = [
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) =
let(
@ -35,7 +39,7 @@ function _nz_worley3_border(p, nbrs, dist) =
b = [sorted[1][0], sorted[1][1], sorted[1][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) =
let(

View File

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

View File

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