1
0
mirror of https://github.com/JustinSDK/dotSCAD.git synced 2025-01-17 14:18:13 +01:00
dotSCAD/docs/lib3x-nz_perlin3s.md

61 lines
1.5 KiB
Markdown
Raw Normal View History

2020-04-06 13:17:50 +08:00
# nz_perlin3s
2020-03-06 19:40:18 +08:00
2020-04-06 13:17:50 +08:00
Returns 3D [Perlin noise](https://en.wikipedia.org/wiki/Perlin_noise) values at (x, y, z) coordinates.
**Since:** 2.3
## Parameters
- `points` : A list of `[x, y, z]` coordinates.
- `seed` : The random seed. If it's ignored, a randomized value will be used.
## Examples
use <util/rand.scad>;
use <noise/nz_perlin2s.scad>;
use <noise/nz_perlin3s.scad>;
2020-03-06 19:40:18 +08:00
points = [
for(y = [0:.2:10])
[
for(x = [0:.2:10])
[x, y]
]
];
2020-04-06 13:17:50 +08:00
2020-03-06 19:40:18 +08:00
seed = rand(0, 256);
2020-04-06 13:17:50 +08:00
2020-03-06 19:40:18 +08:00
points_with_h = [
for(ri = [0:len(points) - 1])
2020-03-29 11:14:26 +08:00
let(ns = nz_perlin2s(points[ri], seed))
2020-03-06 19:40:18 +08:00
[
for(ci = [0:len(ns) - 1])
[points[ri][ci][0], points[ri][ci][1], ns[ci] + 1]
]
];
2020-04-06 13:17:50 +08:00
2020-03-06 19:40:18 +08:00
h_scale = 1.5;
for(row = points_with_h) {
for(i = [0:len(row) - 1]) {
p = row[i];
pts = [
for(z = [0:.2:p[2] * h_scale]) [p[0], p[1], z]
];
2020-03-29 11:14:26 +08:00
noise = nz_perlin3s(pts, seed);
2020-03-06 19:40:18 +08:00
for(j = [0:len(pts) - 1]) {
if(noise[j] > 0) {
2020-03-06 19:50:13 +08:00
color(
2020-04-06 13:17:50 +08:00
pts[j][2] < 1 ? "green" :
pts[j][2] < 1.5 ? "Olive" : "white")
2020-03-06 19:40:18 +08:00
translate(pts[j])
cube(.2);
}
}
}
}
2020-04-06 13:17:50 +08:00
2020-03-06 19:50:13 +08:00
color("LimeGreen")
2020-03-06 19:40:18 +08:00
linear_extrude(.2)
square(10);
2021-02-24 21:09:54 +08:00
![nz_perlin3s](images/lib3x-nz_perlin3s-1.JPG)