1
0
mirror of https://github.com/JustinSDK/dotSCAD.git synced 2025-08-06 06:47:46 +02:00

return cells

This commit is contained in:
Justin Lin
2020-03-30 15:25:09 +08:00
parent 7c92e0ac5a
commit a2a68f11af
3 changed files with 40 additions and 18 deletions

View File

@@ -16,10 +16,14 @@ function _neighbors(fcord, seed, cell_w) = [
]; ];
function _nz_worley2_classic(p, nbrs, dist) = function _nz_worley2_classic(p, nbrs, dist) =
min([ let(
cells = [
for(nbr = nbrs) for(nbr = nbrs)
_distance(nbr, p, dist) [nbr[0], nbr[1], _distance(nbr, p, dist)]
]); ],
sorted = sort(cells, by = "idx", idx = 2)
)
sorted[0];
function _nz_worley2_border(p, nbrs, dist) = function _nz_worley2_border(p, nbrs, dist) =
let( let(
@@ -32,7 +36,7 @@ function _nz_worley2_border(p, nbrs, dist) =
b = [sorted[1][0], sorted[1][1]], b = [sorted[1][0], sorted[1][1]],
m = (a + b) / 2 m = (a + b) / 2
) )
(p - m) * (a - m); [a[0], a[1], (p - m) * (a - m)];
function _nz_worley2(p, seed, cell_w, dist) = function _nz_worley2(p, seed, cell_w, dist) =
let( let(

View File

@@ -1,4 +1,5 @@
use <experimental/nz_worley2.scad>; use <experimental/nz_worley2.scad>;
use <util/dedup.scad>;
size = [100, 50]; size = [100, 50];
cell_w = 10; cell_w = 10;
@@ -8,14 +9,23 @@ seed = 51;
points = [ points = [
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, nz_worley2(x, y, seed, cell_w, dist)] [x, y]
]; ];
max_dist = max([for(p = points) p[2]]); cells = [for(p = points) nz_worley2(p[0], p[1], seed, cell_w, dist)];
for(p = points) {
c = p[2] / max_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]) color([c, c, c])
linear_extrude(c * max_dist) linear_extrude(cells[i][2])
translate([p[0], p[1]]) 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); square(1);
} }

View File

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