mirror of
https://github.com/xibyte/jsketcher
synced 2025-12-06 08:25:19 +01:00
27 lines
409 B
JavaScript
27 lines
409 B
JavaScript
export default function pertrub([x, y, z]) {
|
|
|
|
const s = x + y + z;
|
|
x = pertrubFloat(x + 3 + s);
|
|
y = pertrubFloat(y + 5 + s);
|
|
z = pertrubFloat(z + 7 + s);
|
|
|
|
const r = Math.sqrt(x*x + y*y + z*z);
|
|
|
|
return [
|
|
x/r,
|
|
y/r,
|
|
z/r
|
|
];
|
|
}
|
|
|
|
function pertrubFloat(x) {
|
|
return xorshift32(Math.round(x * 1e8)) ;
|
|
}
|
|
|
|
function xorshift32(x) {
|
|
x ^= x << 13;
|
|
x ^= x >> 17;
|
|
x ^= x << 5;
|
|
return x;
|
|
}
|
|
|