1
0
mirror of https://github.com/JustinSDK/dotSCAD.git synced 2025-01-18 06:38:14 +01:00

add pnoise_contour

This commit is contained in:
Justin Lin 2020-03-07 21:52:04 +08:00
parent 49ef2ab03b
commit 7bfe89ef64
2 changed files with 29 additions and 0 deletions

View File

@ -0,0 +1,25 @@
use <experimental/pnoise2.scad>;
INFINITY = 1e200 * 1e200;
function _pnoise_contour_step_sub(x, y, current_noise, seed, step_leng, step_angle, heading, min_delta, maybe_heading, close_noise, maybe_x, maybe_y, theta) =
theta >= heading + 90 ? [maybe_x, maybe_y, maybe_heading] :
let(
nx = x + step_leng * cos(theta),
ny = y + step_leng * sin(theta),
new_noise = pnoise2([[nx, ny]], seed)[0],
delta = abs(new_noise - current_noise)
)
delta < min_delta ?
_pnoise_contour_step_sub(x, y, current_noise, seed, step_leng, step_angle, heading, delta, theta, new_noise, nx, ny, theta + step_angle) :
_pnoise_contour_step_sub(x, y, current_noise, seed, step_leng, step_angle, heading, min_delta, maybe_heading, close_noise, maybe_x, maybe_y, theta + step_angle);
function _pnoise_contour_step(x, y, heading, seed, step_leng, step_angle) =
_pnoise_contour_step_sub(x, y, pnoise2([[x, y]], seed)[0], seed, step_leng, step_angle, heading, INFINITY, heading, -1, -1, -1, heading - 90);
function _pnoise_contour(x, y, heading, seed, steps, step_leng, step_angle, i = 0) =
i == steps ? [[x, y]] :
let(
xyh = _pnoise_contour_step(x, y, heading, seed, step_leng, step_angle)
)
concat([[x, y]], _pnoise_contour(xyh[0], xyh[1], xyh[2], seed, steps, step_leng, step_angle, i + 1));

View File

@ -0,0 +1,4 @@
use <experimental/_impl/_pnoise_contour_impl.scad>;
function pnoise_contour(x, y, seed = 1, steps = 50, step_leng = 0.2, step_angle = 12) =
_pnoise_contour(x, y, seed % 360, seed, steps, step_leng, step_angle);