Skip to content

blindman67/SimplexNoiseJS

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 

Repository files navigation

SimplexNoiseJS

A JavaScript rewrite of typescript Open-Simplex-Noise an implementation of OpenSimplex noise

The rewrite provides a 15-20% performance improvement on the typescript implementation, file size reduction from 24.28K to 14.66K, and a reduced runtime memory footprint.

Demo

A demo can be found at codepen Simplex Noise Example

Example

const seed = Date.now();
const [width, height] = [888, 222];
const canvas = document.createElement("canvas");
const ctx = canvas.getContext("2d");
const imageData = ctx.createImageData(width, height);
const openSimplex = openSimplexNoise(seed);
const zoom = 8;
var x, y, index = 0;
for (y = 0; y < height; y++) {
  for (x = 0; x < width; x++) {
    const value = (openSimplex.noise2D(x / zoom, y / zoom) + 1) * 128;
    imageData.data[index++] = value;
    imageData.data[index++] = value;
    imageData.data[index++] = value;
    imageData.data[index++] = 255;
  }
}
ctx.putImageData(imageData, 0, 0)

API

function openSimplexNoise

creation openSimplexNoise(seed) => API

API.noise2D (x, y) => -1 < number < 1

API.noise3D (x, y, z) => -1 < number < 1

API.noise4D (x, y, z, w) => -1 < number < 1

Releases

No releases published

Packages

No packages published