npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

perlin.ts

v1.0.2

Published

A small, fast, classical Perlin noise generator that uses CPU. Without any dependencies.

Readme

Classical Perlin Noise

A library for 1D, 2D, 3D, and 4D classical Perlin noise in TypeScript. See the visual test cases here.

Generating Noise

The library exposes a Perlin class. Each instance provides the following methods:

import { Perlin } from 'perlin.ts';
const perlin = new Perlin();

// All methods following return a noise value between -1 and 1

// Generating Single Noise
// x, y, z, w: number
perlin.noise1d(x);
perlin.noise2d(x, y);
perlin.noise3d(x, y, z);
perlin.noise4d(x, y, z, w);

// Generating Fractal Noise
// x, y, z, w: number
// See the next section for fractal options details.
perlin.fractalNoise1d(x, fractalOptions1D);
perlin.fractalNoise2d(x, y, fractalOptions2D);
perlin.fractalNoise3d(x, y, z, fractalOptions3D);
perlin.fractalNoise4d(x, y, z, w, fractalOptions4D);

Here you can view the documentation, which contains detailed descriptions of all the thins in the library.

Generating Fractal Noise

By adding different iterations of noise (octaves), where we successively increment the frequencies in regular steps (lacunarity) and decrease the amplitude (gain) of the noise we can obtain a finer granularity in the noise and get more fine detail. This technique is called "fractal Brownian Motion" (fBM), or simply "fractal noise". -- the book of shaders

import {
  FractalOptions1D,
  FractalOptions2D,
  FractalOptions3D,
  FractalOptions4D,
  Perlin,
} from 'perlin.ts';
const perlin: Perlin = new Perlin();

// Base 1D fractal noise (equivalent to calling perlin.noise1d(0.5))
perlin.fractalNoise1d(0.5);

// Advanced case
/*
octaves — Number of noise layers (octaves). Default: 1.0
amplitude — Initial amplitude (noise strength). Default: 1.0
persistence — Amplitude decay factor between octaves. Default: 1.0
frequency — Initial frequency per component (noise density). Default: { x: 1.0 }
lacunarity — Frequency growth factor per component between octaves. Default: { x: 1.0 }
offset — The offset of each coordinate for every layer. Default: { x: 0.0 }
*/
const options1d: FractalOptions1D = {
  octaves: 5,
  amplitude: 1.0,
  persistence: 1.5,
  frequency: { x: 0.001 },
  lacunarity: { x: 2.0 },
  offset: { x: 21.0 },
};
perlin.fractalNoise1d(10, options1d); // Return a 1d fractal noise value between -1 and 1.

// And more.
const options2d: FractalOptions2D = {
  octaves: 5,
  amplitude: 1.0,
  persistence: 1.5,
  frequency: { x: 0.001, y: 0.002 },
  lacunarity: { x: 2.0, y: 2.0 },
  offset: { x: 21.0, y: 22 },
};
perlin.fractalNoise2d(10, 11, options2d); // Return a 2d fractal noise value between -1 and 1.

const options3d: FractalOptions3D = {
  octaves: 5,
  amplitude: 1.0,
  persistence: 1.5,
  frequency: { x: 0.001, y: 0.002, z: 0.0003 },
  lacunarity: { x: 2.0, y: 2.0, z: 2.0 },
  offset: { x: 21.0, y: 22, z: 23 },
};
perlin.fractalNoise3d(10, 11, 12, options3d); // Return a 3d fractal noise value between -1 and 1.

const options4d: FractalOptions4D = {
  octaves: 5,
  amplitude: 1.0,
  persistence: 1.5,
  frequency: { x: 0.001, y: 0.002, z: 0.0003, w: 0.0004 },
  lacunarity: { x: 2.0, y: 2.0, z: 2.0, w: 2.0 },
  offset: { x: 21.0, y: 22, z: 23, w: 24 },
};
perlin.fractalNoise4d(10, 11, 12, 13, options4d); // Return a 4d fractal noise value between -1 and 1.

Other methods

import { Perlin, SmoothstepOrder } from 'perlin.ts';
const perlin = new Perlin(12345); // Create an instance using a random seed of 12345.
perlin.setSeed(54321); // Reset value of the random seed.
perlin.getSeed(); // Get value of the random seed.

perlin.shufflePerm(); // Shuffle the hash table within the instance.

const perlin2 = new Perlin(54321, SmoothstepOrder.Cubic); // Create an instance using a cubic smoothstep.

Installation

npm install perlin.ts

Node.js, Require.js (AMD) and Common.js supported: const Perlin = require('perlin.ts');

Otherwise a perlin global is created.

Todo

  • Add an optional matrix as a property to the fractal options, which describes how to linearly transform the input vector per layer.
  • Add an optional parameter to the noiseXd and the fractalNoiseXd methods, which use to receives the analytical gradient of the noise function.