diff --git a/src/experimental/_impl/_worley_noise_impl.scad b/src/experimental/_impl/_worley_noise_impl.scad new file mode 100644 index 00000000..d1e86c5b --- /dev/null +++ b/src/experimental/_impl/_worley_noise_impl.scad @@ -0,0 +1,6 @@ +use ; + +function _manhattan(v) = sum([for(d = v) abs(d)]); + +function _chebyshev(p1, p2) = + max([for(i = [0:len(p1) - 1]) abs(p1[i] - p2[i])]); \ No newline at end of file diff --git a/src/experimental/worley_noise.scad b/src/experimental/worley_noise.scad new file mode 100644 index 00000000..2da8a69d --- /dev/null +++ b/src/experimental/worley_noise.scad @@ -0,0 +1,10 @@ +use ; + +function worley_noise(p, points, dist = "euclidean") = + let( + dists = dist == "euclidean" ? [for(i = [0:len(points) - 1]) norm(points[i] - p)] : + dist == "manhattan" ? [for(i = [0:len(points) - 1]) _manhattan(points[i] - p)] : + dist == "chebyshev" ? [for(i = [0:len(points) - 1]) _chebyshev(points[i], p)] : + assert("Unknown distance option") + ) + min(dists); \ No newline at end of file