Coder Social home page Coder Social logo

open-simplex-noise-js's Introduction

OpenSimplex Noise

TypeScript implementation of OpenSimplex noise.

Example

import { makeNoise2D } from "open-simplex-noise";
// import { makeNoise2D } from "https://deno.land/x/open_simplex_noise/mod.ts"

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()); // Using current date as seed

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);

Example output

Fractal Noise

For fractal noise results, which typically involves scaling frequencies and stacking octaves, see joshforisha/fractal-noise-js (Deno: fractal_noise, NPM: fractal-noise). The functions there can be used with this library's noise algorithm to obtain varied results like the following:

Example fractal noise output

API

Each noise function returns a float between -1 and 1, exclusive: (-1.0, 1.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

makeNoise2D (seed: number) => Noise2D

Initializes and returns a function to generate 2D noise.

makeNoise3D (seed: number) => Noise3D

Initializes and returns a function to generate 3D noise.

makeNoise4D (seed: number) => Noise4D

Initializes and returns a function to generate 4D noise.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.