Fractal Flame
also: flame fractal, flame algorithm
First appeared 1992 · Scott Draves — Created by Scott Draves in 1992 as an open-source iterated-function-system variant; later ported widely (e.g. the Apophysis editor). · timeline ↗
inventor-coined Name · coined by Scott Draves (1992) — Coined by its creator: Scott Draves named the technique "fractal flame" (1992).
In one line A class of iterated function system (IFS) fractal that generalises the IFS with non-linear "variation" functions, log-density (tone-mapped) accumulation, and structural colouring — producing the smooth, luminous, smoke-or-flame-like forms popularised by software such as Apophysis.
The code
The actual sketch behind the demo above — sandboxed and reproducible. This is the whole thing.
fractal-flame/index.html
// Fractal flame (Scott Draves, 1992) — a chaos game over an Iterated Function
// System whose maps are affine transforms composed with non-linear "variations"
// (sinusoidal, spherical, swirl, horseshoe…). Each iterate lands in a bin; we
// accumulate hit DENSITY (+ a colour coordinate per function), then tone-map
// with a logarithmic transfer so dense cores glow without clipping. Vanilla canvas.
const SEED = (Math.random() * 1e9) | 0;
let s = SEED || 1;
const rnd = () => (s = (s * 1103515245 + 12345) & 0x7fffffff) / 0x7fffffff;
const cv = document.getElementById('c');
const ctx = cv.getContext('2d');
const DIM = Math.floor(Math.min(window.innerWidth, window.innerHeight));
const RES = Math.min(DIM, 560);
cv.width = cv.height = RES;
cv.style.width = cv.style.height = DIM + 'px';
// palette (colour by which function fired)
const PAL = [[255,90,60],[255,190,40],[80,200,255],[190,90,255],[60,255,160]];
// variations
function V(k, x, y) {
const r2 = x*x + y*y, r = Math.sqrt(r2) || 1e-9, th = Math.atan2(y, x);
switch (k) {
case 0: return [x, y]; // linear
case 1: return [Math.sin(x), Math.sin(y)]; // sinusoidal
case 2: return [x / r2, y / r2]; // spherical
case 3: return [x*Math.sin(r2) - y*Math.cos(r2), x*Math.cos(r2) + y*Math.sin(r2)]; // swirl
case 4: return [(x - y)*(x + y)/r, 2*x*y/r]; // horseshoe
case 5: return [Math.sin(th)*Math.cos(r), Math.cos(th)*Math.sin(r)]; // handkerchief-ish
}
return [x, y];
}
// build 3–4 random functions: affine + a chosen variation + colour
const NF = 3 + (rnd() * 2 | 0);
const F = [];
for (let i = 0; i < NF; i++) {
// contractive affine maps (rotation+scale < 1, modest translation) so the
// attractor stays bounded and dense — reliably flame-like across seeds
const ang = rnd() * Math.PI * 2;
const sc = 0.35 + rnd() * 0.5; // scale 0.35–0.85 (contractive)
const co = Math.cos(ang) * sc, si = Math.sin(ang) * sc;
F.push({
m: [co, -si, (rnd()*2-1)*0.9, si, co, (rnd()*2-1)*0.9], // rotate-scale + translate
v: (rnd() * 6) | 0,
col: PAL[i % PAL.length],
w: 0.4 + rnd(),
});
}
const wsum = F.reduce((s, f) => s + f.w, 0);
// accumulation buffers
const R = new Float32Array(RES * RES), G = new Float32Array(RES * RES), B = new Float32Array(RES * RES), A = new Float32Array(RES * RES);
let px = rnd() * 2 - 1, py = rnd() * 2 - 1;
let cr = 0, cg = 0, cb = 0;
const SCALE = RES / 4.2, OX = RES / 2, OY = RES / 2;
function iterate(n) {
for (let i = 0; i < n; i++) {
// choose a function by weight
let t = rnd() * wsum, k = 0; while ((t -= F[k].w) > 0 && k < NF - 1) k++;
const f = F[k], m = f.m;
const ax = m[0]*px + m[1]*py + m[2], ay = m[3]*px + m[4]*py + m[5];
const [vx, vy] = V(f.v, ax, ay);
px = vx; py = vy;
// drift the running colour toward this function's colour
cr = (cr + f.col[0]) / 2; cg = (cg + f.col[1]) / 2; cb = (cb + f.col[2]) / 2;
if (i < 20) continue; // discard the transient
const sx = (px * SCALE + OX) | 0, sy = (py * SCALE + OY) | 0;
if (sx >= 0 && sx < RES && sy >= 0 && sy < RES) {
const idx = sy * RES + sx;
R[idx] += cr; G[idx] += cg; B[idx] += cb; A[idx] += 1;
}
}
}
const img = ctx.createImageData(RES, RES);
function render() {
let max = 1;
for (let i = 0; i < A.length; i++) if (A[i] > max) max = A[i];
const lm = 1 / Math.log(max + 1);
const d = img.data;
for (let i = 0; i < A.length; i++) {
const a = A[i];
if (a === 0) { d[i*4+3] = 255; continue; }
const bright = Math.log(a + 1) * lm; // logarithmic density tone-map
const inv = 1 / a;
d[i*4] = Math.min(255, R[i] * inv * bright * 1.6);
d[i*4+1] = Math.min(255, G[i] * inv * bright * 1.6);
d[i*4+2] = Math.min(255, B[i] * inv * bright * 1.6);
d[i*4+3] = 255;
}
ctx.putImageData(img, 0, 0);
}
function loop() { iterate(120000); render(); requestAnimationFrame(loop); }
loop();How it works
Run the chaos game over a set of affine transforms, but extend it: 1. Each transform's output is passed through one or more non-linear "variation" functions (sinusoidal, spherical, swirl…), blended per transform — this is what gives flames their organic curves. 2. Plot the orbit into an accumulation buffer that counts hits per pixel and carries a colour coordinate per transform. 3. Tone-map by the logarithm of density so bright cores and faint wisps both render, then apply gamma and colour. The image is fully determined by the set of transforms, variations, weights and colour parameters — a compact "genome" of ~100+ numbers.
Parameters
variations: array — The nonlinear variation functions blended each iteration.iterations: number — Points plotted via the chaos game; more iterations reduce noise.gamma: number — Tone-mapping gamma applied to the accumulated log-density buffer.symmetry: number — Rotational/dihedral symmetry imposed on the function set.
Lineage
Frequently combined with
- Genetic Algorithm (Evolutionary Art) · 1 work
Works using this algorithm (2)
Last updated 2026-07-16