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:
parent
49ef2ab03b
commit
7bfe89ef64
25
src/experimental/_impl/_pnoise_contour_impl.scad
Normal file
25
src/experimental/_impl/_pnoise_contour_impl.scad
Normal 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));
|
4
src/experimental/pnoise_contour.scad
Normal file
4
src/experimental/pnoise_contour.scad
Normal 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);
|
Loading…
x
Reference in New Issue
Block a user