[READ-ONLY] Mirror of https://github.com/flo-bit/every-noise. javascript noise class with lots of features flo-bit.github.io/every-noise/
javascript noise procedural-generation
0

Configure Feed

Select the types of activity you want to include in your feed.

added minified version

flo-bit (Jan 7, 2023, 1:23 AM +0100) 7ca85ea1 0c5236a6

+8
+8
noise.min.js
··· 1 + class Vector{constructor(t,i,s,e){return void 0!=t&&"object"==typeof t&&void 0!=t.x?this.copy(t):this.set(t||0,i||0,s,e),this.isVector=!0,this.is2D=void 0==s,this.is3D=!this.is2D&&void 0==e,this.is4D=!this.is2D&&!this.is3D,this}copy(t){return this.x=t.x,this.y=t.y,this.z=t.z,this.w=t.w,this}clone(){return new Vector(this.x,this.y,this.z,this.w)}set(t,i,s,e){return"number"!=typeof t&&void 0!=t.x?this.copy(t):(void 0==i&&void 0==s&&void 0==e&&(this.is2D&&this.set(t,t),this.is3D&&this.set(t,t,t),this.is4D&&this.set(t,t,t,t)),this.x=t,this.y=i,this.z=s,this.w=e,this)}add(t,i,s,e){return"number"!=typeof t&&void 0!=t.x?this.add(t.x,t.y,t.z,t.w):(void 0==i&&void 0==s&&void 0==e&&(this.is2D&&this.add(t,t),this.is3D&&this.add(t,t,t),this.is4D&&this.add(t,t,t,t)),this.x+=t||0,this.y+=i||0,this.z+=s||0,this.w+=e||0,this)}sub(t,i,s,e){return"number"!=typeof t&&void 0!=t.x?this.sub(t.x,t.y,t.z,t.w):(void 0==i&&void 0==s&&void 0==e&&(this.is2D&&this.sub(t,t),this.is3D&&this.sub(t,t,t),this.is4D&&this.sub(t,t,t,t)),this.x-=t||0,this.y-=i||0,this.z-=s||0,this.w-=e||0,this)}mult(t,i,s,e){return"number"!=typeof t&&void 0!=t.x?this.mult(t.x,t.y,t.z,t.w):(void 0==i&&void 0==s&&void 0==e&&(this.is2D&&this.mult(t,t),this.is3D&&this.mult(t,t,t),this.is4D&&this.mult(t,t,t,t)),this.x*=t||0,this.y*=i||0,this.z*=s||0,this.w*=e||0,this)}div(t,i,s,e){return"number"!=typeof t&&void 0!=t.x?this.div(m.x,t.y,t.z,t.w):(void 0==i&&void 0==s&&void 0==e&&(this.is2D&&this.div(t,t),this.is3D&&this.div(t,t,t),this.is4D&&this.div(t,t,t,t)),this.x/=t||0,this.y/=i||0,this.z/=s||0,this.w/=e||0,this)}dot(t){return this.x*t.x+this.y*t.y+(void 0!=this.z?this.z*t.z:0)+(void 0!=this.w?this.w*t.w:0)}cross(t){return this.is3D&&t.is3D||console.warn("cross(vec) only supports 3D vectors"),new Vector(this.y*t.z-this.z*t.y,this.z*t.x-this.x*t.z,this.x*t.y-this.y*t.x)}dist(t,i,s,e){if("number"!=typeof t&&void 0!=t.x)return this.dist(t.x,t.y,t.z,t.w);let o=0,r=this.x-t;o+=r*r;let h=(this.y||0)-(i||0);o+=h*h;let n=(this.z||0)-(s||0);o+=n*n;let $=(this.w||0)-(e||0);return Math.sqrt(o+=$*$)}distance(t,i,s,e){return this.dist(t,i,s,e)}distanceTo(t,i,s,e){return this.dist(t,i,s,e)}length(){return Math.sqrt(this.x*this.x+this.y*this.y+(this.z||0)*(this.z||0)+(this.w||0)*(this.w||0))}setLength(t){return this.mult(t/this.length()),this}limit(t){let i=this.length();return i>t&&this.mult(i/t),this}heading(){return this.is2D||console.warn("heading() only supports 2D vectors"),Math.atan2(this.x,this.y)}rotate(t){this.is2D||console.warn("rotate(a) only supports 2D vectors");let i=Math.cos(t),s=Math.sin(t);return this.set(i*this.x-s*this.y,s*this.x+i*this.y),this}angleBetween(t){let i;return Math.acos(this.dot(t)/(this.length()*t.length()))}angleTo(t){return this.angleBetween(t)}equals(t){return this.x==t.x&&this.y==t.y&&this.z==t.z&&this.w==t.w}normalize(){return this.setLength(1),this}mag(){return this.length()}setMag(t){return this.setLength(t),this}manhattanLength(){return this.x+this.y+(this.z||0)+(this.w||0)}lerp(t,i){let s=t.x-this.x,e=t.y-this.y,o=t.z-this.z,r=t.w-this.w;return this.add(s*i,e*i,o*i,r*i),this}stringDescription(){let t=(this.is2D?"2D":this.is3D?"3D":"4D")+" vec ("+this.x+", "+this.y;return void 0!=this.z&&(t+=", "+this.z),void 0!=this.w&&(t+=", "+this.w),t+=")"}static fromAngle2D(t,i){let s=new Vector(Math.cos(t),Math.sin(t));return i&&s.setLength(i),s}static random2D(t,i=Math.random){let s=new Vector(2*i()-1,2*i()-1);for(;s.length()>1;)s.set(2*i()-1,2*i()-1);return t&&s.setLength(t),s}static random3D(t,i=Math.random){let s=new Vector(2*i()-1,2*i()-1,2*i()-1);for(;s.length()>1;)s.set(2*i()-1,2*i()-1,2*i()-1);return t&&s.setLength(t),s}static breakIntoParts(t,i,s){if(void 0==t||void 0==i||!t.isVector||!i.isVector)return;s=Math.floor(s||2);let e=[t.clone()];for(let o=1;o<s;o++)e.push(t.clone().lerp(i,o/s));return e.push(i.clone()),e}}(function(){function t(i,s,e){function o(h,n){if(!s[h]){if(!i[h]){var $="function"==typeof require&&require;if(!n&&$)return $(h,!0);if(r)return r(h,!0);var a=Error("Cannot find module '"+h+"'");throw a.code="MODULE_NOT_FOUND",a}var l=s[h]={exports:{}};i[h][0].call(l.exports,function(t){return o(i[h][1][t]||t)},l,l.exports,t,i,s,e)}return s[h].exports}for(var r="function"==typeof require&&require,h=0;h<e.length;h++)o(e[h]);return o}return t})()({1:[function(t,i,s){/*! 2 + * jsrand - https://github.com/DomenicoDeFelice/jsrand 3 + * 4 + * Copyright (c) 2014-2020 Domenico De Felice 5 + * Released under the MIT License 6 + * 7 + * @license 8 + */ "use strict";function e(t,i){(null==i||i>t.length)&&(i=t.length);for(var s=0,e=Array(i);s<i;s++)e[s]=t[s];return e}function o(t){return(o="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function r(t){null==t?this.randomize():this.seed(t)}r.prototype={},r.seed=r.prototype.seed=function(t){return null==t?this._seed:(this._mz=123456789,this._mw=this._seed=t)},r.randomize=r.prototype.randomize=function(){return this.seed(1+Math.floor(4294967295*Math.random()))},r.getState=r.prototype.getState=function(){return{seed:this._seed,mz:this._mz,mw:this._mw}},r.setState=r.prototype.setState=function(t){if(null==t||"object"!==o(t)||"number"!=typeof t.seed||"number"!=typeof t.mz||"number"!=typeof t.mw)throw Error("Invalid state.");this._seed=t.seed,this._mz=t.mz,this._mw=t.mw},r.random=r.prototype.random=function(){null==this._seed&&this.randomize();var t=this._mz,i=this._mw;return t=4294967295&36969*(65535&t)+(t>>16),i=4294967295&18e3*(65535&i)+(i>>16),this._mz=t,this._mw=i,.5+(4294967295&(t<<16)+i)/4294967296},r.inRange=r.prototype.inRange=function(t,i){return t+this.random()*(i-t)},r.intInRange=r.prototype.intInRange=function(t,i){return t+Math.floor(this.random()*(i-t+1))},r.choice=r.prototype.choice=function(t){if(0===t.length)throw Error("Cannot choose random element from empty array.");return t[this.intInRange(0,t.length-1)]},r.choices=r.prototype.choices=function(t,i){for(var s=Array(i),e=0;e<i;e++)s[e]=this.choice(t);return s},r.sample=r.prototype.sample=function(t,i){if(i>t.length)throw Error("Sample size cannot exceed population size.");if(i===t.length){var s;return function t(i){if(Array.isArray(i))return e(i)}(s=t)||function t(i){if("undefined"!=typeof Symbol&&Symbol.iterator in Object(i))return Array.from(i)}(s)||function t(i,s){if(i){if("string"==typeof i)return e(i,s);var o=Object.prototype.toString.call(i).slice(8,-1);return"Object"===o&&i.constructor&&(o=i.constructor.name),"Map"===o||"Set"===o?Array.from(i):"Arguments"===o||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(o)?e(i,s):void 0}}(s)||function t(){throw TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}for(var o,r=t.length-1,h=Array(i),n={},$=0;$<i;$++){do o=this.intInRange(0,r);while(n[o]);h[$]=t[o],n[o]=!0}return h},r.shuffle=r.prototype.shuffle=function(t){for(var i=t.length-1;0<i;i--){var s=this.intInRange(0,i-1),e=t[i];t[i]=t[s],t[s]=e}return t},r._oldSrand=void 0,r.noConflict=function(){return r},i.exports=r},{},],2:[function(t,i,s){"use strict";var e,o=(e=t("./jsrand.js"),e&&e.__esModule?e:{default:e});o.default._oldSrand=window.Srand,o.default.noConflict=function(){return window.Srand=o.default._oldSrand,o.default},window.Srand=o.default},{"./jsrand.js":1},]},{},[2]);class Noise{static defaultUp=new Vector(0,1,0);static Simplex=(function(){let t=.5*(Math.sqrt(3)-1),i=(3-Math.sqrt(3))/6,s=1/3,e=1/6,o=(Math.sqrt(5)-1)/4,r=(5-Math.sqrt(5))/20,h=t=>0|Math.floor(t),n=new Float64Array([1,1,-1,1,1,-1,-1,-1,1,0,-1,0,1,0,-1,0,0,1,0,-1,0,1,0,-1,]),$=new Float64Array([1,1,0,-1,1,0,1,-1,0,-1,-1,0,1,0,1,-1,0,1,1,0,-1,-1,0,-1,0,1,1,0,-1,1,0,1,-1,0,-1,-1,]),a=new Float64Array([0,1,1,1,0,1,1,-1,0,1,-1,1,0,1,-1,-1,0,-1,1,1,0,-1,1,-1,0,-1,-1,1,0,-1,-1,-1,1,0,1,1,1,0,1,-1,1,0,-1,1,1,0,-1,-1,-1,0,1,1,-1,0,1,-1,-1,0,-1,1,-1,0,-1,-1,1,1,0,1,1,1,0,-1,1,-1,0,1,1,-1,0,-1,-1,1,0,1,-1,1,0,-1,-1,-1,0,1,-1,-1,0,-1,1,1,1,0,1,1,-1,0,1,-1,1,0,1,-1,-1,0,-1,1,1,0,-1,1,-1,0,-1,-1,1,0,-1,-1,-1,0,]);function l(t){let i=new Uint8Array(512);for(let s=0;s<256;s++)i[s]=s;for(let e=0;e<255;e++){let o=e+~~(t()*(256-e)),r=i[e];i[e]=i[o],i[o]=r}for(let h=256;h<512;h++)i[h]=i[h-256];return i}return{createNoise2D:function s(e=Math.random){let o=l(e),r=new Float64Array(o).map(t=>n[t%12*2]),$=new Float64Array(o).map(t=>n[t%12*2+1]);return function s(e,n){let a=0,l=0,p=0,_=(e+n)*t,d=h(e+_),u=h(n+_),c=(d+u)*i,f=e-(d-c),y=n-(u-c),v,w;f>y?(v=1,w=0):(v=0,w=1);let g=f-v+i,D=y-w+i,N=f-1+2*i,x=y-1+2*i,z=255&d,P=255&u,b=.5-f*f-y*y;if(b>=0){let S=z+o[P],A=r[S],M=$[S];b*=b,a=b*b*(A*f+M*y)}let k=.5-g*g-D*D;if(k>=0){let I=z+v+o[P+w],V=r[I],B=$[I];k*=k,l=k*k*(V*g+B*D)}let F=.5-N*N-x*x;if(F>=0){let R=z+1+o[P+1],L=r[R],U=$[R];F*=F,p=F*F*(L*N+U*x)}return 70*(a+l+p)}},createNoise3D:function t(i=Math.random){let o=l(i),r=new Float64Array(o).map(t=>$[t%12*3]),n=new Float64Array(o).map(t=>$[t%12*3+1]),a=new Float64Array(o).map(t=>$[t%12*3+2]);return function t(i,$,l){let p,_,d,u,c=(i+$+l)*s,f=h(i+c),y=h($+c),v=h(l+c),w=(f+y+v)*e,g=i-(f-w),D=$-(y-w),N=l-(v-w),x,z,P,b,S,A;g>=D?D>=N?(x=1,z=0,P=0,b=1,S=1,A=0):g>=N?(x=1,z=0,P=0,b=1,S=0,A=1):(x=0,z=0,P=1,b=1,S=0,A=1):D<N?(x=0,z=0,P=1,b=0,S=1,A=1):g<N?(x=0,z=1,P=0,b=0,S=1,A=1):(x=0,z=1,P=0,b=1,S=1,A=0);let M=g-x+e,k=D-z+e,I=N-P+e,V=g-b+2*e,B=D-S+2*e,F=N-A+2*e,R=g-1+3*e,L=D-1+3*e,U=N-1+3*e,j=255&f,C=255&y,X=255&v,Y=.6-g*g-D*D-N*N;if(Y<0)p=0;else{let q=j+o[C+o[X]];Y*=Y,p=Y*Y*(r[q]*g+n[q]*D+a[q]*N)}let T=.6-M*M-k*k-I*I;if(T<0)_=0;else{let O=j+x+o[C+z+o[X+P]];T*=T,_=T*T*(r[O]*M+n[O]*k+a[O]*I)}let E=.6-V*V-B*B-F*F;if(E<0)d=0;else{let G=j+b+o[C+S+o[X+A]];E*=E,d=E*E*(r[G]*V+n[G]*B+a[G]*F)}let H=.6-R*R-L*L-U*U;if(H<0)u=0;else{let J=j+1+o[C+1+o[X+1]];H*=H,u=H*H*(r[J]*R+n[J]*L+a[J]*U)}return 32*(p+_+d+u)}},createNoise4D:function t(i=Math.random){let s=l(i),e=new Float64Array(s).map(t=>a[t%32*4]),n=new Float64Array(s).map(t=>a[t%32*4+1]),$=new Float64Array(s).map(t=>a[t%32*4+2]),p=new Float64Array(s).map(t=>a[t%32*4+3]);return function t(i,a,l,_){let d,u,c,f,y,v=(i+a+l+_)*o,w=h(i+v),g=h(a+v),D=h(l+v),N=h(_+v),x=(w+g+D+N)*r,z=i-(w-x),P=a-(g-x),b=l-(D-x),S=_-(N-x),A=0,M=0,k=0,I=0;z>P?A++:M++,z>b?A++:k++,z>S?A++:I++,P>b?M++:k++,P>S?M++:I++,b>S?k++:I++;let V=A>=3?1:0,B=M>=3?1:0,F=k>=3?1:0,R=I>=3?1:0,L=A>=2?1:0,U=M>=2?1:0,j=k>=2?1:0,C=I>=2?1:0,X=A>=1?1:0,Y=M>=1?1:0,q=k>=1?1:0,T=I>=1?1:0,O=z-V+r,E=P-B+r,G=b-F+r,H=S-R+r,J=z-L+2*r,K=P-U+2*r,Q=b-j+2*r,W=S-C+2*r,Z=z-X+3*r,tt=P-Y+3*r,ti=b-q+3*r,ts=S-T+3*r,te=z-1+4*r,to=P-1+4*r,tr=b-1+4*r,th=S-1+4*r,tn=255&w,t$=255&g,ta=255&D,tl=255&N,tp=.6-z*z-P*P-b*b-S*S;if(tp<0)d=0;else{let t_=tn+s[t$+s[ta+s[tl]]];tp*=tp,d=tp*tp*(e[t_]*z+n[t_]*P+$[t_]*b+p[t_]*S)}let td=.6-O*O-E*E-G*G-H*H;if(td<0)u=0;else{let tu=tn+V+s[t$+B+s[ta+F+s[tl+R]]];td*=td,u=td*td*(e[tu]*O+n[tu]*E+$[tu]*G+p[tu]*H)}let tc=.6-J*J-K*K-Q*Q-W*W;if(tc<0)c=0;else{let tf=tn+L+s[t$+U+s[ta+j+s[tl+C]]];tc*=tc,c=tc*tc*(e[tf]*J+n[tf]*K+$[tf]*Q+p[tf]*W)}let tm=.6-Z*Z-tt*tt-ti*ti-ts*ts;if(tm<0)f=0;else{let ty=tn+X+s[t$+Y+s[ta+q+s[tl+T]]];tm*=tm,f=tm*tm*(e[ty]*Z+n[ty]*tt+$[ty]*ti+p[ty]*ts)}let tv=.6-te*te-to*to-tr*tr-th*th;if(tv<0)y=0;else{let tw=tn+1+s[t$+1+s[ta+1+s[tl+1]]];tv*=tv,y=tv*tv*(e[tw]*te+n[tw]*to+$[tw]*tr+p[tw]*th)}return 27*(d+u+c+f+y)}}}})();static firstDefined(...t){for(let i=0;i<t.length;i++)if(void 0!==t[i])return t[i]}constructor(t){if(t=t||{},this.pos=new Vector(0,0,0),this._seed=Noise.firstDefined(t.seed,t.s,1e6*Math.random()),this.prng=new Srand(this._seed),this.octaves=Noise.firstDefined(t.octaves,t.oct,0),this.gain=Noise.firstDefined(t.gain,t.persistence,t.per,.5),this.lacunarity=Noise.firstDefined(t.lacunarity,t.lac,2),this.layers=void 0,this.noise2D=void 0,this.noise3D=void 0,this.noise4D=void 0,this.octaves>0||void 0!=t.layers){this.layers=[];for(let i=0;i<this.octaves||t.layers&&i<t.layers.length;i++){let s=void 0!=t.layers&&t.layers.length>i?t.layers[i]:{};if(s.seed=this.prng.inRange(0,1e9),t.all)for(let e of Object.keys(t.all))s[e]=t.all[e];!0!=s.isNoise?this.layers.push(new Noise(s)):this.layers.push(s)}}else{let o=this.prng.random.bind(this.prng);this.noise2D=Noise.Simplex.createNoise2D(o),this.noise3D=Noise.Simplex.createNoise3D(o),this.noise4D=Noise.Simplex.createNoise4D(o)}this.scale=Noise.firstDefined(t.scale,t.scl,1),this.power=Noise.firstDefined(t.power,t.pow,1),this.shift=Noise.firstDefined(t.shift,new Vector(t.x||.357,t.y||.579,t.z||.248,t.w||0)),this.erosion=Noise.firstDefined(t.erosion,t.ero,0),this.delta=Noise.firstDefined(t.delta,t.del,1e-4*this.scale),this.amp=Noise.firstDefined(t.amplitude,t.amp),this.sharpness=Noise.firstDefined(t.sharpness,t.sharp,0),this.steps=t.steps,this.min=Noise.firstDefined(t.min,-1),this.max=Noise.firstDefined(t.max,1),this.combine=void 0,this.mod=t.mod,this.warp=void 0,this.warp2=void 0,this.warpNoise=void 0,this.warpNoise2=void 0,void 0!=t.warp&&(this.warp=t.warp,t.warpNoise&&(this.warpNoise=t.warpNoise,this.warpNoise.seed=this.prng.inRange(0,1e9),!0!=this.warpNoise.isNoise&&(this.warpNoise=new Noise(t.warpNoise)))),void 0!=t.warp2&&(this.warp2=t.warp2,t.warpNoise2&&(this.warpNoise2=t.warpNoise2,!0!=this.warpNoise2.isNoise&&(this.warpNoise2=new Noise(t.warpNoise2)))),this.defaultUp=t.defaultUp,t.amps&&this.multiplyAmps(t.amps),this.central=t.central,this.tileX=t.tileX,this.tileY=t.tileY,t.tile&&(this.tileX=!0,this.tileY=!0),this.isNoise=!0,this.derivative=void 0}get scale(){return this.getPropertyAtPosition("_scale",this.pos)}set scale(t){this._scale=t,this.checkProperty("_scale")}get power(){return this.getPropertyAtPosition("_power",this.pos)}set power(t){this._power=t,this.checkProperty("_power")}get octaves(){return this.getPropertyAtPosition("_octaves",this.pos)}set octaves(t){this._octaves=t,this.checkProperty("_octaves")}get gain(){return this.getPropertyAtPosition("_gain",this.pos)}set gain(t){this._gain=t,this.checkProperty("_gain")}get lacunarity(){return this.getPropertyAtPosition("_lacunarity",this.pos)}set lacunarity(t){this._lacunarity=t,this.checkProperty("_lacunarity")}get erosion(){return this.getPropertyAtPosition("_erosion",this.pos)}set erosion(t){this._erosion=t,this.checkProperty("_erosion")}get amp(){return this.getPropertyAtPosition("_amp",this.pos)}set amp(t){this._amp=t,this.checkProperty("_amp")}get combine(){return this.getPropertyAtPosition("_combine",this.pos)}set combine(t){this._combine=t,this.checkProperty("_combine")}get sharpness(){return this.getPropertyAtPosition("_sharpness",this.pos)}set sharpness(t){this._sharpness=t,this.checkProperty("_sharpness")}get warp(){return this.getPropertyAtPosition("_warp",this.pos)}set warp(t){this._warp=t,this.checkProperty("_warp")}get warp2(){return this.getPropertyAtPosition("_warp2",this.pos)}set warp2(t){this._warp2=t,this.checkProperty("_warp2")}get steps(){return this.getPropertyAtPosition("_steps",this.pos)}set steps(t){this._steps=t,this.checkProperty("_steps")}get min(){return this.getPropertyAtPosition("_min",this.pos)}set min(t){this._min=t,this.checkProperty("_min")}get max(){return this.getPropertyAtPosition("_max",this.pos)}set max(t){this._max=t,this.checkProperty("_max")}get seed(){return this._seed}set seed(t){this.setSeed(t)}setSeed(t){this._seed=void 0!=t?t:1e9*Math.random(),this.prng&&(this.prng=new Srand(this._seed));let i=this.prng.random.bind(this.prng);if(this.noise2D&&(this.noise2D=new Noise.Simplex.createNoise2D(i)),this.noise3D&&(this.noise3D=new Noise.Simplex.createNoise3D(i)),this.noise4D&&(this.noise4D=new Noise.Simplex.createNoise4D(i)),this.layers)for(let s=0;s<this.layers.length;s++)this.layers[s].seed=this.prng.inRange(0,1e9);for(let e of Object.keys(this))void 0!=this[e]&&this[e].isNoise&&(this[e].seed=this.prng.inRange(0,1e9));return t}checkProperty(t){let i=this[t];void 0==i||"number"==typeof i||i.isNoise||(void 0==i.seed&&(i.seed=this.seed),this[t]=new Noise(i))}getPropertyAtPosition(t,i){let s=this[t];if(void 0!=s){if("number"==typeof s)return s;if(s.isNoise)return void 0!=i?s.get(i.x,i.y,i.z,i.w):s}}shiftBy(t,i,s,e){this.shift.x+=t||0,this.shift.y+=i||0,this.shift.z+=s||0,this.shift.w+=e||0}multiplyAmps(t){if(void 0!=this.layers)for(let i=0;i<this.layers.length&&i<t.length;i++)this.layers[i].amp*=t[i]}lerp(t,i,s){return(i-t)*s+t}tilePosition(){let t=this.pos.x,i=this.pos.y,s=0,e=0,o=0,r=0;this.tileX&&(s=Math.sin(t*Math.PI*2),e=Math.cos(t*Math.PI*2)),this.tileY&&(o=Math.sin(i*Math.PI*2),r=Math.cos(i*Math.PI*2)),this.tileX&&!this.tileY?this.pos.set(s,e+i):this.tileY&&!this.tileX?this.pos.set(o+t,r):this.tileX&&this.tileY&&this.pos.set(s,e,o,r)}warpPosition(){let t=this.warp;if(void 0==t||0==t)return;let i=this.pos.x,s=this.pos.y,e=this.pos.z,o=this.pos.w;this.warpNoise&&this.warpNoise.pos.copy(this.pos);let r=this.warpNoise||this,h=r.scale;i+=r.getFBM(i-74.98*h,s+41.33*h,void 0!=e?e+76.56*h:void 0,void 0,!0)*t,s+=r.getFBM(i+1.23*h,s+5.79*h,void 0!=e?e+12.85*h:void 0,void 0,!0)*t,void 0!=e&&(e+=r.getFBM(i+11.47*h,s+17.98*h,e+23.56*h,void 0,!0)*t),void 0!=o&&(o+=r.getFBM(i+54.47*h,s+34.98*h,e+76.56*h,o+45.98*h,!0)*t);let n=this.warp2;if(void 0==n||0==n){this.pos.set(i,s,e,o);return}this.warpNoise2&&this.warpNoise2.pos.copy(this.pos),h=(r=this.warpNoise2||this).scale,i+=r.getFBM(i+11.47*h,s+17.98*h,void 0,void 0,!0)*n,s+=r.getFBM(i-73.98*h,s+44.33*h,void 0,void 0,!0)*n,void 0!=o&&(e+=r.getFBM(i+11.23*h,s+53.79*h,e+96.31*h,void 0,!0)*n),void 0!=o&&(o+=r.getFBM(i+11.23*h,s+53.79*h,e+96.31*h,o+23.56*h,!0)*n),this.pos.set(i,s,e,o)}getFBM(t,i,s,e,o){let r=this.scale;if(void 0==this.layers)return void 0!=this.noise4D&&void 0!=e?(this.lastNoiseCall="noise4D",this.noise4D(t*r,i*r,s*r,e*r)):void 0!=this.noise3D&&void 0!=s?(this.lastNoiseCall="noise3D",this.noise3D(t*r,i*r,s*r)):void 0!=this.noise2D?(this.lastNoiseCall="noise2D",this.noise2D(t*r,i*r)):0;let h=void 0!=this.defaultUp?this.defaultUp(t,i,s):Noise.defaultUp,n=1,$=1,a=r,l=this.lacunarity,p=this.gain;this.sum=this.sum||new Vector,this.sum.set(0,0,0);let _=0,d=o?0:this.erosion,u=this.octaves;for(let c=0;c<=u&&c<this.layers.length;c++){let f=this.layers[c],y=f.amp||1,v=f.get(t*a,i*a,void 0!=s?s*a:void 0,void 0!=e?e*a:void 0)*$*y;if(d>0){let w=f.getDerivative(t*a,i*a,s*a);w.setLength($*y),this.sum.add(w);_+=v*(Math.abs(1-h.angleTo(this.sum)/Math.PI)*d+1-d)}else _+=v;$*=p,a*=l,n+=$*y}return _/n}getNoise(t,i,s,e){t=t||0,i=i||0,this.pos.set(t+this.shift.x,i+this.shift.y,void 0!=s?s+this.shift.z:void 0,void 0!=e?e+this.shift.w:void 0),(this.tileX||this.tileY)&&this.tilePosition(),(this.warp||this.warp2)&&this.warpPosition();let o=this.getFBM(this.pos.x,this.pos.y,this.pos.z,this.pos.w),r=this.power;if(r&&1!=r&&(o=(Math.pow((o+1)*.5,r)-.5)*2),void 0!=this.sharpness&&0!=this.sharpness){let h=this.sharpness,n=(Math.abs(o)-.5)*2,$=(.5-Math.abs(o))*2;o=this.lerp(o,n,Math.max(0,h)),o=this.lerp(o,$,Math.abs(Math.min(0,h)))}this.clamp&&(o=Math.max(o=Math.min(o,1),-1)),this.mod&&(o=this.mod(o,this.pos,this,up)),this.combine&&(o*=this.combine);let a=this.steps;return void 0!=a&&a>=2?(Math.floor((o+1)*(a=Math.round(a))*.5)/(a-1)-.5)*2:o}getDerivative(t,i,s,e){e=e||this.get(t,i,s);let o=this.delta,r=(this.central?this.get(t-o,i,s):e)-this.get(t+o,i,s),h=(this.central?this.get(t,i-o,s):e)-this.get(t,i+o,s),n=(this.central?this.get(t,i,s-o):e)-this.get(t,i,s+o);return void 0==this.derivative&&(this.derivative=new Vector),this.derivative.set(r,h,n),this.derivative.normalize(),this.derivative}mapNormalizedToMinMax(t){return(t+1)*.5*(this.max-this.min)+this.min}mapMinMaxToNormalized(t){return((t-this.min)/(this.max-this.min)-.5)*2}getNormalized(t,i,s,e){return"number"==typeof t?this.getNoise(t,i,s,e):this.getNoise(t.x,t.y,t.z,t.w)}getNorm(t,i,s,e){return this.getNormalized(t,i,s,e)}get(t,i,s,e){return this.mapNormalizedToMinMax(this.getNormalized(t,i,s,e))}}