How to use simplex-noise - 10 common examples

To help you get started, we’ve selected a few simplex-noise examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github blaze33 / droneWorld / src / voxel / voxel.worker.js View on Github external
/* eslint-env worker */

import SimplexNoise from 'simplex-noise'
import {
  Geometry,
  MeshNormalMaterial
} from 'three'
// import { Geometry } from 'three/src/core/Geometry'
// import { MeshNormalMaterial } from 'three/src/materials/MeshNormalMaterial'
import { MarchingCubes } from 'three/examples/jsm/objects/MarchingCubes.js'
import { SimplifyModifier } from 'three/examples/jsm/modifiers/SimplifyModifier.js'
import { voxelSize } from './constants'

const simple = new SimplifyModifier()
const noise = new SimplexNoise('123')

const generateVoxels = (i, j, k, zMax) => {
  console.time([i, j, k].toString())
  let n = 0
  let noGeometry = true
  let noiseValue
  let geometry
  const dim = 32
  const positions = new Float32Array(dim * dim * dim)
  const effect = new MarchingCubes(dim, new MeshNormalMaterial(), false, false)
  effect.isolation = 0

  let n128, n64, n32, n16, n8, n4
  const fbm = (x, y, z) => {
    n128 = noise.noise3D(x / 128, y / 128, z / 128)
    n64 = noise.noise3D(x / 64, y / 64, z / 64)
github Larkenx / Rotten-Soup / src / assets / js / game / map / generation / RandomSimplex.js View on Github external
export function randomSimplexMap(width, height, zoom) {
	// we want to zoom in a lot so that the land is larger, so the width & height will be half
	let w = ~~(width / zoom)
	let h = ~~(height / zoom)
	let gameMap = new GameMap(w, h)
	console.log(w, h)
	// base textures
	/* GOOD SEEDS
        - 908234
    */
	let seed1 = 908234
	let seed2 = 908234
	let rng1 = RNG.create(seed1)
	let rng2 = RNG.create(seed2)
	let gen1 = new SimplexNoise(rng1.nextDouble.bind(rng1))
	let gen2 = new SimplexNoise(rng2.nextDouble.bind(rng2))
	let frequency = 1.5

	const mobDistribution = {
		// ORC: 1,
		// EMPOWERED_ORC: 1,
		// KOBOLD: 1,
		GOBLIN: 1,
		// BAT: 1,
		RAT: 3,
		WILD_GOAT: 3
	}

	// const createActor = (actorString, x, y, id) => {
	// 	switch (actorString) {
	// 		case 'ORC':
github amelierosser / medium / examples / src / js / texture3d / index.js View on Github external
document.body.appendChild(renderer.canvas);

// Scene
const scene = new Scene();

// Camera
const camera = new PerspectiveCamera({
  fov: 45
});

camera.position.set(35, -25, 35);
camera.lookAt();

const SIZE = 64;

const simplex = new SimplexNoise(Math.random);

const scale = 0.035;
// const scale = 1;
const src = new Uint8Array(SIZE * SIZE * SIZE);
for (let k = 0; k < SIZE; k += 1) {
  for (let j = 0; j < SIZE; j += 1) {
    for (let i = 0; i < SIZE; i += 1) {
      src[i + j * SIZE + k * SIZE * SIZE] =
        Math.abs(simplex.noise3D(i * scale, j * scale, k * scale)) * 256;
    }
  }
}

const texture3d = new Texture3d({
  src,
  size: SIZE
github rolyatmax / sketches / src / endemic-meter.js View on Github external
main: (canvas, settings) => {
    canvas.callbackTokens = canvas.callbackTokens || []
    while (canvas.callbackTokens.length) {
      cIC(canvas.callbackTokens.pop())
    }

    const ctx = window.ctx = canvas.getContext('2d')
    ctx.globalCompositeOperation = 'darker'
    const rand = new Alea(settings.seed)
    const simplex = new SimplexNoise(rand)
    const colors = colorPalettes[rand() * colorPalettes.length | 0]
    const color = colors[rand() * colors.length | 0]
    ctx.fillStyle = tinycolor(color).setAlpha(settings.alpha / 100).toRgbString()

    function drawCircle (j) {
      const token = rIC(() => {
        for (let i = 0; i < settings.dotCount; i++) {
          const angle = (i / settings.dotCount) * Math.PI * 2 + j / Math.PI
          const noiseZoom = settings.noiseZoom / 100
          const noise = simplex.noise2D(angle / noiseZoom, j / noiseZoom)
          const spread = settings.spread / 100
          const radius = settings.radius + noise * j * spread
          const x = Math.cos(angle) * radius + canvas.width / 2
          const y = Math.sin(angle) * radius + canvas.height / 2
          ctx.fillRect(x, y, 1, 1)
        }
github Thorium-Sim / thorium / server / src / processes / crm.js View on Github external
import App from "../app";
import { pubsub } from "../helpers/subscriptionManager";
import SimplexNoise from "simplex-noise";
import * as THREE from "three";
import { randomFromList } from "../classes/generic/damageReports/constants";
function distance3d(coord2, coord1) {
  const { x: x1, y: y1, z: z1 } = coord1;
  let { x: x2, y: y2, z: z2 } = coord2;
  return Math.sqrt((x2 -= x1) * x2 + (y2 -= y1) * y2 + (z2 -= z1) * z2);
}

const noise = new SimplexNoise(Math.random);
let tick = 0;
const interval = 1000 / 20;

function crmContactMove() {
  tick++;
  App.flights
    .filter(f => f.running === true)
    .forEach(f => {
      f.simulators
        .map(s => App.simulators.find(ss => ss.id === s))
        .forEach((simulator, i) => {
          let triggerUpdate = false;
          const crm = App.systems.find(
            s => s.simulatorId === simulator.id && s.class === "Crm"
          );
          if (!crm) return;
github pissang / papercut-box-art / src / simplexCuts.js View on Github external
export default function (config, seed) {
    var simplex = new SimplexNoise(function () {
        return seed;
    });
    var values = [];
    var m = 200;
    var n = 200;
    var scale = Math.max(config.randomScale, 1);
    var levels = Math.min(Math.max(Math.round(config.paperCount), 1), 10);
    for (var x = 0; x < m; x++) {
        for (var y = 0; y < n; y++) {
            values.push(simplex.noise2D(x / m * scale, y / n * scale));
        }
    }
    var thresholds = Array.from(Array(levels).keys()).map(function (a) {
        return a / levels - config.randomOffset;
    });
github rolyatmax / sketches / src / antic-grandmom.js View on Github external
ctx.setup = ctx.resize = function () {
  center = [ctx.width / 2, ctx.height / 2]
  ctx.clearRect(0, 0, ctx.width, ctx.height)
  rand = new Alea(settings.seed)
  randX = randomNormal.source(rand)(center[0], settings.sigma)
  randY = randomNormal.source(rand)(center[1], settings.sigma)
  simplex = new SimplexNoise(rand)
  lines = []
  clearTimeout(token)
  token = setTimeout(createLine, 0)
}
github eranimo / terranova / src / simulation / worldgen / world.worker.ts View on Github external
function generateMoisture(
  options: IWorldMapGenOptions,
  heightmap: ndarray,
  sealevel: number,
  cellTypes: ndarray,
  riverMap: ndarray,
): ndarray {
  const { seed, size: { width, height } } = options;
  const rng = new (Alea as any)(seed);
  const moistureMap = ndarray(new Int16Array(width * height), [width, height]);
  const simplex = new SimplexNoise(rng);
  fill(moistureMap, (x, y) => {
    if (cellTypes.get(x, y) === ECellType.LAND) {
      const nx = x / width - 0.5;
      const ny = y / height - 0.5;
      const moisture = ((simplex.noise2D(3 * nx, 3 * ny) + 1) / 2);
      const inlandRatio = (heightmap.get(x, y) - sealevel) / (255 - sealevel);
      return (moisture * (1 - inlandRatio)) * 500;
    }
    return 0;
  });
  let cells = [];
  const scale = Math.max(width, height) / 250;
  for (let x = 0; x < width; x++) {
    for (let y = 0; y < height; y++) {
      if (riverMap.get(x, y) === 1) {
        const inlandRatio = (heightmap.get(x, y) - sealevel) / (255 - sealevel);
github stasilo / retrace.gl / src / dtos / dynamic-scene / index.js View on Github external
export default async (src) => {
    const simplex = new SimplexNoise();

    if(cachedSrc != src) {
        transpiledSrc = babel.transformSync(src, {
            presets: [babelEnvPreset],
            plugins: [
                [babelDecoratorPlugin, {legacy: true}],
                babelObjSpreadPlugin,
                [babelPipesPlugin, {proposal: 'smart'}]
            ]
        });

        cachedSrc = src;
    }

    return eval(transpiledSrc.code);
}
github PlotterClub / penplotPlayground / util / random.js View on Github external
export const setSeed = (seed, opt) => {
  if (typeof seed === 'number' || typeof seed === 'string') {
    currentRandom = seedRandom(seed, opt);
  } else {
    currentRandom = defaultRandom;
  }
  currentSimplex = new SimplexNoise(currentRandom);
}

simplex-noise

simplex-noise is a fast simplex noise implementation in Javascript. Works in node and in the browser.

MIT
Latest version published 4 months ago

Package Health Score

69 / 100
Full package analysis

Popular simplex-noise functions