mirror of
https://github.com/JustinSDK/dotSCAD.git
synced 2025-01-17 14:18:13 +01:00
symmetric
This commit is contained in:
parent
53e86a14fa
commit
c3d5484fde
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 cell_pt(fcord, grid_w, seed, x, y) =
|
||||
function cell_pt(fcord, grid_w, seed, x, y, gw, gh) =
|
||||
let(
|
||||
nx = fcord[0] + x,
|
||||
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),
|
||||
sd2 = _lookup_noise_table(sd1 * 255 + sd_base)
|
||||
)
|
||||
[(nx + sd1) * grid_w, (ny + sd2) * grid_w];
|
||||
|
||||
// 21-nearest-neighbor
|
||||
function _neighbors(fcord, seed, grid_w) =
|
||||
function _neighbors(fcord, seed, grid_w, gw, gh) =
|
||||
concat(
|
||||
[
|
||||
for(y = [-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)],
|
||||
[for(y = [-1:1]) cell_pt(fcord, grid_w, seed, -2, y)],
|
||||
[for(y = [-1:1]) cell_pt(fcord, grid_w, seed, 2, y)]
|
||||
[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, gw, gh)],
|
||||
[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, gw, gh)]
|
||||
);
|
||||
|
||||
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,
|
||||
half_region_size = region_size * 0.5,
|
||||
shape = shape_square(grid_w * 3),
|
||||
cell_nbrs_lt = [for(cy = [0:grid_w:size[1]])
|
||||
for(cx = [0:grid_w:size[0]])
|
||||
gw = size[0] / grid_w,
|
||||
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(
|
||||
nbrs = _neighbors(
|
||||
[floor(cx / grid_w), floor(cy / grid_w)],
|
||||
sd,
|
||||
grid_w
|
||||
grid_w,
|
||||
gw,
|
||||
gh
|
||||
),
|
||||
p = nbrs[4],
|
||||
points = concat(
|
||||
|
Loading…
x
Reference in New Issue
Block a user