forked from JustinSDK/dotSCAD
-
Notifications
You must be signed in to change notification settings - Fork 0
/
worley_noise_ball.scad
58 lines (50 loc) · 1.44 KB
/
worley_noise_ball.scad
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
use <noise/nz_worley3s.scad>
use <sweep.scad>
radius = 25;
a_step = 5;
tile_w = 10;
dist = "euclidean"; // [euclidean, manhattan, chebyshev, "border"]
noise_style = "CELL_R"; // [CELL_R, NOISE]
noise_factor = 1;
seed = rands(0, 255, 1)[0];
module worley_noise_ball() {
theta_tau_lt = [
for(tau = [-90:a_step:90])
[for(theta = 360; theta >= 0; theta = theta - a_step)
[theta, tau]]
];
function to_xyz(polar) =
let(
r = polar[0],
theta = polar[1],
tau = polar[2],
z = r * sin(tau),
r2 = r * cos(tau),
x = r2 * cos(theta),
y = r2 * sin(theta)
)
[x, y, z];
cells = [
for(row = theta_tau_lt)
nz_worley3s(
[for(theta_tau = row) to_xyz([radius, theta_tau[0], theta_tau[1]])],
seed,
tile_w,
dist
)
];
sections = [
for(ri = [0:len(theta_tau_lt) - 1])
[
for(ci = [0:len(theta_tau_lt[0]) - 1])
let(
theta_tau = theta_tau_lt[ri][ci],
off_r = noise_style == "CELL_R" ? norm([cells[ri][ci][0], cells[ri][ci][1], cells[ri][ci][2]]) : cells[ri][ci][3],
nr = radius + off_r * noise_factor
)
to_xyz([nr, theta_tau[0], theta_tau[1]])
]
];
sweep(sections);
}
worley_noise_ball();