1
0
mirror of https://github.com/JustinSDK/dotSCAD.git synced 2025-03-14 02:59:42 +01:00

user can define his own xs

This commit is contained in:
Justin Lin 2020-03-05 20:23:17 +08:00
parent f1d864e44a
commit ae32838d1a
2 changed files with 9 additions and 7 deletions

View File

@ -1,10 +1,10 @@
function _pnoise1(x, n, slopes) =
function _pnoise1(x, n, gradients) =
let(
lo = floor(x),
hi = (lo + 1) % n,
dist = x - lo,
loPos = slopes[lo] * dist,
hiPos = -slopes[hi] * (1 - dist),
loPos = gradients[lo] * dist,
hiPos = -gradients[hi] * (1 - dist),
u = pow(dist, 3) * (dist * (dist * 6 - 15) + 10)
)
loPos * (1 - u) + hiPos * u;

View File

@ -1,11 +1,13 @@
use <experimental/_impl/_pnoise1.scad> ;
function pnoise1(from, to, step = 0.5) =
function pnoise1(xs, gradients) =
let(
from = floor(min(xs)),
to = ceil(max(xs)),
n = to - from + 1,
slopes = rands(-1, 1, n)
grads = is_undef(gradients) ? rands(-1, 1, n) : gradients
)
[
for(x = [0:step:n - 1])
[from + x, _pnoise1(x, n, slopes)]
for(x = xs)
_pnoise1(x, n, grads)
];