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 🙏

© 2024 – Pkg Stats / Ryan Hefner

quick-perlin-noise-js

v1.0.3

Published

Fast, public domain implementation of perlin noise.

Downloads

71

Readme

quick-noise.js

Fast, public domain implementation of perlin noise.

Works either in the browser or as a common.js module. In the browser it's functions will be available on the quickNoise object.

This started as a port of Sean Barrett's excellent stb_perlin.h library but no longer has much in common with it.

At the time of this writing (Sep 2015) it is the fastest out of the noise modules (on my computer), beating most of the others by at least 10%. However, the optimizations applied in it require that your runtime support Typed Arrays (I do not plan on removing this restriction in the future, since most runtimes support this).

Documentation

function quickNoise.noise(x, y, z, xWrap=0, yWrap=0, zWrap=0)

  • x, y, z are numbers.
  • xWrap, yWrap, and zWrap are integer powers of two between 0 and 256. (0 and 256 are equivalent). If these aren't provided, they default to 0.

This implements Ken Perlin's revised noise function from 2002, in 3D. It computes a random value between -1 and 1 for the coordinate x, y, z, where adjacent values are continuous with a period of 1 (Values at integer points are entirely unrelated).

This function is seeded. That is, it will return the same results when called with the same arguments, across successive program runs. An unseeded version may be created with the quickNoise.create function. The table it is seeded is the one from the stb_perlin.h library.

function quickNoise.create(tableOrRng=Math.random)

tableOrRng must either be:

  • A function that takes 0 arguments and returns a uniformly distributed random number between 0 and 1 (like Math.random).
  • An array of length 256, where the array is generated by shuffling all integers between 0 and 255 (inclusive).

If no argument (or a bad argument) is provided, it defaults to Math.random.

This creates a perlin noise generation function. For more documentation about the function returned by this call, see the documentation for quickNoise.noise, above.

If you provide a function, this will be used to generate the permutation table, and will not be called after this function returns (it won't be used by the function returned by this one, if that makes any sense).

The array argument provided in case you want to provide a specific permutation table.

Usage Example

var UPSCALE = 4;
var canvas = document.getElementsByTagName('canvas')[0];
var ctx = canvas.getContext('2d');
var pixels = null;
var pixBuf = null;
function resize() {
	canvas.style.width = window.innerWidth+"px";
	canvas.style.height = window.innerHeight+"px";
	canvas.height = window.innerHeight/UPSCALE;
	canvas.width = window.innerWidth/UPSCALE;
	pixels = ctx.createImageData(canvas.width, canvas.height);
	pixBuf = new Uint32Array(pixels.data.buffer);
}

window.addEventListener('resize', resize);
resize();
var zValue = 0;
function go() {
	var resolution = 10;
	zValue += 1.0 / 60.0;
	var width = ctx.canvas.width;
	var height = ctx.canvas.height;
	var i = 0;
	for (var y = 0; y < height; ++y) {
		for (var x = 0; x < width; ++x) {
			var noiseR = quickNoise.noise(x/resolution, y/resolution, 0+zValue)+1;
			var noiseG = quickNoise.noise(x/resolution, y/resolution, 1+zValue)+1;
			var noiseB = quickNoise.noise(x/resolution, y/resolution, 2+zValue)+1;
			var r = Math.floor(noiseR * 128) & 0xff;
			var g = Math.floor(noiseG * 128) & 0xff;
			var b = Math.floor(noiseB * 128) & 0xff;
			pixBuf[i++] = r | (g << 8) | (b << 16) | 0xff000000;
		}
	}
	ctx.putImageData(pixels, 0, 0);
	requestAnimationFrame(go);
}
go();

License

Public Domain (CC0).