mirror of
https://github.com/JustinSDK/dotSCAD.git
synced 2025-08-05 14:27:45 +02:00
symmetric
This commit is contained in:
15
examples/voronoi/voronoi_torus.scad
Normal file
15
examples/voronoi/voronoi_torus.scad
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
use <experimental/voronoi_square_cells.scad>;
|
||||||
|
use <hull_polyline3d.scad>;
|
||||||
|
use <ptf/ptf_torus.scad>;
|
||||||
|
|
||||||
|
size = [40, 80];
|
||||||
|
grid_w = 5;
|
||||||
|
cells = voronoi_square_cells(size, grid_w);
|
||||||
|
|
||||||
|
$fn = 4;
|
||||||
|
|
||||||
|
for(cell = cells) {
|
||||||
|
cell_poly = [for(p = cell[1]) ptf_torus(size, p, [10, 5], [360, 360])];
|
||||||
|
|
||||||
|
hull_polyline3d(cell_poly, thickness = 1);
|
||||||
|
}
|
@@ -4,28 +4,32 @@ _noise_table = [0.592157, 0.627451, 0.537255, 0.356863, 0.352941, 0.0588235, 0.5
|
|||||||
|
|
||||||
function _lookup_noise_table(i) = _noise_table[i % 256];
|
function _lookup_noise_table(i) = _noise_table[i % 256];
|
||||||
|
|
||||||
function cell_pt(fcord, grid_w, seed, x, y) =
|
function cell_pt(fcord, grid_w, seed, x, y, gw, gh) =
|
||||||
let(
|
let(
|
||||||
nx = fcord[0] + x,
|
nx = fcord[0] + x,
|
||||||
ny = fcord[1] + y,
|
ny = fcord[1] + y,
|
||||||
sd_base = abs(nx + ny * grid_w),
|
sd_x = nx < 0 ? nx + gw :
|
||||||
|
nx >= gw ? nx % gw : nx,
|
||||||
|
sd_y = ny < 0 ? ny + gh :
|
||||||
|
ny >= gh ? ny % gh : ny,
|
||||||
|
sd_base = abs(sd_x + sd_y * grid_w),
|
||||||
sd1 = _lookup_noise_table(seed + sd_base),
|
sd1 = _lookup_noise_table(seed + sd_base),
|
||||||
sd2 = _lookup_noise_table(sd1 * 255 + sd_base)
|
sd2 = _lookup_noise_table(sd1 * 255 + sd_base)
|
||||||
)
|
)
|
||||||
[(nx + sd1) * grid_w, (ny + sd2) * grid_w];
|
[(nx + sd1) * grid_w, (ny + sd2) * grid_w];
|
||||||
|
|
||||||
// 21-nearest-neighbor
|
// 21-nearest-neighbor
|
||||||
function _neighbors(fcord, seed, grid_w) =
|
function _neighbors(fcord, seed, grid_w, gw, gh) =
|
||||||
concat(
|
concat(
|
||||||
[
|
[
|
||||||
for(y = [-1:1])
|
for(y = [-1:1])
|
||||||
for(x = [-1:1])
|
for(x = [-1:1])
|
||||||
cell_pt(fcord, grid_w, seed, x, y)
|
cell_pt(fcord, grid_w, seed, x, y, gw, gh)
|
||||||
],
|
],
|
||||||
[for(x = [-1:1]) cell_pt(fcord, grid_w, seed, x, -2)],
|
[for(x = [-1:1]) cell_pt(fcord, grid_w, seed, x, -2, gw, gh)],
|
||||||
[for(x = [-1:1]) cell_pt(fcord, grid_w, seed, x, 2)],
|
[for(x = [-1:1]) cell_pt(fcord, grid_w, seed, x, 2, gw, gh)],
|
||||||
[for(y = [-1:1]) cell_pt(fcord, grid_w, seed, -2, y)],
|
[for(y = [-1:1]) cell_pt(fcord, grid_w, seed, -2, y, gw, gh)],
|
||||||
[for(y = [-1:1]) cell_pt(fcord, grid_w, seed, 2, y)]
|
[for(y = [-1:1]) cell_pt(fcord, grid_w, seed, 2, y, gw, gh)]
|
||||||
);
|
);
|
||||||
|
|
||||||
function _cells_lt_before_intersection(shape, size, points, pt, half_region_size) =
|
function _cells_lt_before_intersection(shape, size, points, pt, half_region_size) =
|
||||||
|
@@ -8,13 +8,17 @@ function voronoi_square_cells(size, grid_w, seed) =
|
|||||||
region_size = grid_w * 3,
|
region_size = grid_w * 3,
|
||||||
half_region_size = region_size * 0.5,
|
half_region_size = region_size * 0.5,
|
||||||
shape = shape_square(grid_w * 3),
|
shape = shape_square(grid_w * 3),
|
||||||
cell_nbrs_lt = [for(cy = [0:grid_w:size[1]])
|
gw = size[0] / grid_w,
|
||||||
for(cx = [0:grid_w:size[0]])
|
gh = size[1] / grid_w,
|
||||||
|
cell_nbrs_lt = [for(cy = [-grid_w:grid_w:size[1]])
|
||||||
|
for(cx = [-grid_w:grid_w:size[0]])
|
||||||
let(
|
let(
|
||||||
nbrs = _neighbors(
|
nbrs = _neighbors(
|
||||||
[floor(cx / grid_w), floor(cy / grid_w)],
|
[floor(cx / grid_w), floor(cy / grid_w)],
|
||||||
sd,
|
sd,
|
||||||
grid_w
|
grid_w,
|
||||||
|
gw,
|
||||||
|
gh
|
||||||
),
|
),
|
||||||
p = nbrs[4],
|
p = nbrs[4],
|
||||||
points = concat(
|
points = concat(
|
||||||
|
Reference in New Issue
Block a user