Smooth Drift in Processing: Swapping random() for noise()
Use Processing's noise() with a running coordinate to replace jittery random() motion with smooth, controllable drift—plus how to tune detail and verify determinism.
08 Jun 2026, 23:34 UTC

The Jitter Problem
You attach a particle to random(-1, 1) and expect a gentle wander. Instead it teleports in sharp, unrelated directions every frame. random() returns independent values with no memory of the previous call, so position and angle change are uncorrelated. The eye reads that as static, not organic drift.
Perlin Noise: a Smooth Coordinate Field
noise(x) is Processing's implementation of Perlin noise: a function that returns a value, nominally between 0 and 1, that changes smoothly as the input coordinate changes. Nearby inputs produce nearby outputs. There are also noise(x, y) and noise(x, y, z) for two- and three-dimensional fields.
The practical fix is to stop treating each frame as a fresh dice roll. Keep a running coordinate—traditionally called t—advance it by a small, constant amount each frame, and sample noise() at separated offsets for each channel you need.
Worked Example: Side-by-Side Dots
Paste this into the Processing IDE (3.x or 4.x). No special permissions are required; just run the sketch.
float t = 0;
void setup() {
size(600, 200);
noiseSeed(42); // makes the noise sequence repeatable
}
void draw() {
background(240);
// Left: independent random values each frame
float rx = random(0, width / 2);
float ry = random(0, height);
fill(255, 0, 0);
ellipse(rx, ry, 12, 12);
// Right: smooth noise-driven coordinates
float nx = map(noise(t), 0, 1, width / 2, width);
float ny = map(noise(t + 1000), 0, 1, 0, height);
fill(0, 100, 200);
ellipse(nx, ny, 12, 12);
t += 0.01;
}
The red dot jumps; the blue dot glides. The offset 1000 keeps the x and y channels uncorrelated while each stays smooth. map() stretches the nominal 0–1 noise range into screen coordinates.
Diagnostic Checks
- Change
t += 0.01tot += 0.2. The blue dot should start to jump, showing that a large step reintroduces visible discontinuity. - Add
println(noise(t))indraw()for a few frames, then restart the sketch withnoiseSeed(42)insetup(). The printed sequence should repeat exactly, which confirms determinism. - Print the minimum and maximum of
noise()over several thousand samples before relying on exact endpoints; the actual bounds can be narrower than 0 to 1.
Controlling Detail and Cost with noiseDetail()
noiseDetail(octaves, falloff) stacks additional layers of noise on top of the base signal. More octaves add finer wiggles but increase the cost per sample. The default is commonly around four octaves with a falloff of 0.5, but confirm the default in your installed Processing version.
// Finer texture, higher CPU cost
noiseDetail(8, 0.5);
// Coarser, cheaper
noiseDetail(2, 0.5);
If you sample noise hundreds of times per frame, profile before raising octaves. A jump from 4 to 8 octaves can cut frame rate on modest hardware.
Trade-offs and When to Keep random()
- Bounded output:
noise()is not guaranteed to reach exactly 0 or 1. Usemap()with a small margin or sample the actual range in your version. - No true white noise: Discrete events—spawning an item, picking a one-off color, shuffling a list—still belong to
random(). - Step size matters: Keep
tincrements small and consistent, roughly 0.01 to 0.05 per frame.
Check It Yourself
- Run the side-by-side sketch and confirm the blue dot glides while the red dot teleports.
- Verify repeatability: add
noiseSeed(42), print tennoise()values, restart, and compare the output. - Compare
noiseDetail(4, 0.5)againstnoiseDetail(8, 0.5)and watch the frame rate. - If the motion holds smooth and the frame rate is acceptable, the pattern is safe to reuse for camera drift, particle flow, or generative backgrounds.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.