# 雜訊結合雜訊

April 3, 2022

## 碎形布朗運動

``````use <polyline_join.scad>

seed = rand(0, 255);

width = 10;
height = 2;
step = 0.05;

points = [
for(i = [0:width / step])
let(x = i * step)
[x, height * nz_perlin1(x, seed)]
];

polyline_join(points)
circle(.025);
``````

``````use <polyline_join.scad>

seed = rand(0, 255);

width = 10;
height = 2;
step = 0.05;

to = width / step;

points = [
for(i = [0:width / step])
let(x = i * step)
[x, 0.5 * height * nz_perlin1(x * 2, seed)]
];

polyline_join(points)
circle(.025);
``````

``````use <polyline_join.scad>

seed = rand(0, 255);

width = 10;
height = 2;
step = 0.05;

to = width / step;

points = [
for(i = [0:to])
let(x = i * step)
[x, height * nz_perlin1(x, seed) + 0.5 * height * nz_perlin1(x * 2, seed)]
];

polyline_join(points)
circle(.025);
``````

``````use <polyline_join.scad>

function fbm(n, x, amplitude, seed, i = 0) =
i == n ? 0 : amplitude * nz_perlin1(x, seed) + fbm(n, x * 2, amplitude * 0.5, seed, i + 1);

seed = rand(0, 255);

width = 10;
height = 2;
step = 0.05;
n = 3;

points = [
for(i = [0:width / step])
let(x = i * step)
[x, fbm(n, x, height, seed)]
];

polyline_join(points)
circle(.025);
``````

## Worley + Perlin 雜訊

Worley 雜訊〉可以簡單地結合 dotSCAD 的 `sf_thicken` 函式，來建立一個曲面：

``````use <noise/nz_worley2.scad>

size = [30, 30];
grid_w = 15;
mesh_w = 0.2;
thickness = 0.5;
seed = 51;

point_size = size / mesh_w;

sf = [
for(y = [0:point_size.y - 1])
[
for(x = [0:point_size.x - 1])
let(
px = x * mesh_w,
py = y * mesh_w,
nz = nz_worley2(px, py, seed, grid_w)[2]
)
[px, py, nz]
]
];

sf_thicken(sf, thickness);
``````

``````use <noise/nz_worley2.scad>

size = [30, 30];
grid_w = 15;
amplitude = 1;
mesh_w = 0.2;
wave_smoothness = 2;
thickness = 0.5;
dist = "euclidean"; // [euclidean, manhattan, chebyshev, border]
seed = 51;

point_size = size / mesh_w;

sf = [
for(y = [0:point_size.y - 1])
[
for(x = [0:point_size.x - 1])
let(
px = x * mesh_w,
py = y * mesh_w,
nz = nz_worley2(px, py, seed, grid_w, dist)[2],
n = amplitude * nz_perlin2(nz / wave_smoothness, nz / wave_smoothness, seed)
)
[px, py, n]
]
];

sf_thicken(sf, thickness);
``````

`wave_smoothness` 是由來決定取多大片的 Perlin 曲面，值越大，就會在相對小的範圍內取 Perlin 雜訊，出來的曲面變化就越小，也就越平滑，由於相同的雜訊值就是圍成一圈又一圈的圓，這一小片隨機然而連續的曲面，就會形成像是漣漪的曲面：