跳转到内容
查看源码

random自动生成

分类:包 · 清单:use "kernels/";

可重复的随机:整数哈希(各后端位级一致)、值噪声、梯度噪声、分形、细胞、旋度噪声、正态分布等。

Randomness a Kernel can repeat: hashes of whole numbers, the same bits on every backend, the value, gradient, fractal, cellular and curl noise built on them, normal draws, and points spread evenly over a disc.

Layer: Foundation. Uses: no other package.

use "random.entpkg";
  • kernels/cellular.ent — Worley’s cells.
  • kernels/curl.ent — Curl noise.
  • kernels/hash.ent — Hashes of whole numbers, by integer arithmetic, so a point’s hash is the same bits on every backend, read as a number from 0 to 1 or a whole number below a bound.
  • kernels/noise.ent — Value and gradient noise in two and three dimensions, interpolated between hashed corners, and their fractal sums.
  • kernels/sample.ent — Samples drawn: a draw from the normal distribution (gaussian), and point k of n spread evenly over a disc (vogel_point).

tests/ holds scenes and their replays, run on every backend: noise.replay, samples.replay. Every Kernel of the package is reached by one of them.

Used by the animation, darkroom, nebula examples.

函数 简述
worley3(p: Vec3, seed: Int) -> Vec3 Worley’s cells: a random point in each cell of space; how far p is from the nearest (x) and the next nearest (y), and the nearest’s hash (z), 0 to 1.
curl3(p: Vec3, seed: Int) -> Vec3 Curl noise: the curl of three gradient noises, a swirling field with no sources and no sinks; carried by it, smoke keeps its volume.
scramble(v: Int) -> Int A whole number’s bits stirred (Wellons’ lowbias32): every input bit reaches every output bit.
hash_int(x: Int, seed: Int) -> Int A hash of one, two or three whole numbers and a seed: each number multiplied by its own odd constant, so no two share a direction, and the sum of their bits stirred once.
hash_int2(x: Int, y: Int, seed: Int) -> Int
hash_int3(x: Int, y: Int, z: Int, seed: Int) -> Int
unit_of(h: Int) -> Float A hash as a number from 0 up to 1: its top 24 bits.
below_of(h: Int, n: Int) -> Int A hash as a whole number from 0 below n (at least 1): the high word of the hash, read as unsigned, times n. Never below zero, as h % n is for a hash with its top bit set, and drawn from its high bits.
hash1(x: Int, seed: Int) -> Float A random number from 0 up to 1 for a whole number, a grid cell of a plane, or a cell of space.
hash2(c: Vec2, seed: Int) -> Float
hash3(c: Vec3, seed: Int) -> Float
interleaved_noise(q: Vec2) -> Float A pixel’s own number, 0 to 1, for pixel q (interleaved gradient noise): neighbors differ as much as they can, so a step or an angle shifted by it per pixel breaks banding into a fine grain a blur takes away.
fade(t: Float) -> Float Perlin’s quintic: 0 at 0, 1 at 1, flat at both.
corner2(x: Int, y: Int, seed: Int) -> Float A lattice value, -1 to 1.
corner3(x: Int, y: Int, z: Int, seed: Int) -> Float
value2(p: Vec2, seed: Int) -> Float Value noise, -1 to 1: random values at the whole numbers, blended.
value3(p: Vec3, seed: Int) -> Float
slope3(x: Int, y: Int, z: Int, seed: Int, d: Vec3) -> Float A lattice point’s gradient dotted with the offset to d: one of the twelve edge directions of a cube, as Perlin’s improved noise picks.
gradient3(p: Vec3, seed: Int) -> Float Gradient (Perlin) noise, about -1 to 1: smoother than value noise, without its grid-aligned blocks.
fbm2(p: Vec2, octaves: Int, seed: Int) -> Float A fractal sum: octaves layers of noise, each twice as fine and half as strong as the last; about -1 to 1.
fbm3(p: Vec3, octaves: Int, seed: Int) -> Float
ridged3(p: Vec3, octaves: Int, seed: Int) -> Float Ridged noise, 0 to 1: sharp crests where the noise crosses zero, for cracks, veins and mountain ridges.
gaussian(x: Int, seed: Int) -> Float A draw from the normal distribution (mean 0, deviation 1) for whole number x (Box and Muller): two uniform draws, the first kept off zero, so its logarithm is never infinite.
vogel_point(k: Int, n: Int, turn: Float, radius: Float) -> Vec2 Point k of n spread evenly over a disc of radius (Vogel): each a golden angle round from the last, turned by turn, as far out as the root of its share, so equal areas hold equal numbers of points.

noise.replay, samples.replay