TypeScript implementation of OpenSimplex noise
npm install open-simplex-noise
import { makeNoise2D } from "open-simplex-noise";
const [width, height] = [888, 222];
const canvas = document.querySelector("canvas");
const ctx = canvas.getContext("2d");
const imageData = ctx.createImageData(width, height);
const noise2D = makeNoise2D(Date.now());
for (let x = 0; x < width; x++) {
for (let y = 0; y < height; y++) {
const i = (x + y * width) * 4;
const value = (noise2D(x, y) + 1) * 128;
imageData.data[i] = value;
imageData.data[i + 1] = value;
imageData.data[i + 2] = value;
imageData.data[i + 3] = 255;
}
}
ctx.putImageData(imageData, 0, 0);
type Noise2D = (x: number, y: number) => number
type Noise3D = (x: number, y: number, z: number) => number
type Noise4D = (x: number, y: number, z: number, w: number) => number
Initializes and returns a function to generate 2D noise.
Initializes and returns a function to generate 3D noise.
Initializes and returns a function to generate 4D noise.