A tiny (but advanced) noise generation module
I was largely unsatisfied with the options for noise generation that I could find. Often they only provided simplex noise, if they did have perlin noise it lack sizing customization, seeding, or types. So, I decided to take it upon myself to make a smooth noise generator that offered a variety of generation methods with customizable sizes and seeded generation. Enjoy!
npm i squeaker
pnpm add squeaker
yarn add squeaker
For Web and Deno, no install is required! Just put this line at the top of your file:
import squeaker from 'https://cdn.skypack.dev/squeaker';
If you want type support with skypack, follow the directions here
<script src="https://unpkg.com/squeaker"></script>
And use it like you would any other package from UNPKG
Here's the great part: thanks to microbundle, this package supports CJS, UMD, and ESM formats. That means that wherever and however you use this package — in browser or node, with import or require — you should be set, no configuration required.
To create a noise generator, just use one of the named exports!
import {
perlinNoise1dFactory,
perlinNoise2dFactory,
perlinNoise3dFactory,
valueNoise1dFactory,
valueNoise2dFactory,
valueNoise3dFactory,
randomFactory,
interpolationQuintic,
} from 'squeaker';
// create a noise generating function
const noise = perlinNoise2dFactory({ seed: 13223412 });
// and get some smooth random noise
console.log(noise(502.8378, 1003.11)); // 0.48293299950320834
console.log(noise(502.9378, 1003.11)); // 0.44430917275215664
// seed the generator with a random function of your choosing
const customRandom = randomFactory('seed value').random;
// also offers value noise
const noise3d = valueNoise3dFactory({ random: customRandom });
console.log(noise3d(67.37, 12.12, 5 / 83)); // 0.6996699510042976
console.log(noise3d(67.37, 12.19, 6 / 83)); // 0.6684093711981097
// use custom interpolation functions
const noiseVerySmooth = valueNoise3dFactory({
blendFunction: interpolationQuintic,
});
// or start to tile at set intervals
const noiseTiles = perlinNoise2dFactory({
seed: 'example',
xSize: 10,
ySize: 40,
});
console.log(noiseTiles(0.5, 0.5)); // 0.5245568341212135
console.log(noiseTiles(10.5, 40.5)); // 0.5245568341212135
The basic set of tests are in the test script, the coverage script, and the report script. Just run those using your perferred package manager (npm, yarn, pnpm, etc.) to make sure nothing has broken.
Distributed under the MIT License. See LICENSE
for more information.
Find me @illumincrotty on github or @illumincrotty on twitter
If this tool isn't working for you, try one of these: