valueNoise2 (Noise.js)

claude-of-duty · src/world/Noise.js · javascript · MIT
voice, tag:knn-classified

Generates 2D value noise by interpolating random values at integer grid points.

// Source: https://github.com/Leonxlnx/claude-of-duty | License: MIT | Copyright 2026 Leonxlnx
// Provided via justclaw.it.com; keep this notice with the code.
import { hash2 } from '../core/SeededRandom.js';

/** CPU value noise / fbm used for ground shaping and placement masks. */
export function valueNoise2(x, y) {
  const xi = Math.floor(x), yi = Math.floor(y);
  const xf = x - xi, yf = y - yi;
  const u = xf * xf * (3 - 2 * xf);
  const v = yf * yf * (3 - 2 * yf);
  const a = hash2(xi, yi);
  const b = hash2(xi + 1, yi);
  const c = hash2(xi, yi + 1);
  const d = hash2(xi + 1, yi + 1);
  return (a * (1 - u) + b * u) * (1 - v) + (c * (1 - u) + d * u) * v;
}

export function fbm2(x, y, octaves = 4, gain = 0.5) {
  let sum = 0, amp = 0.5, norm = 0;
  for (let i = 0; i < octaves; i++) {
 

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search for more like it.

Get a free API key