06Burning Ship variant — one absolute value turns the set into a ship ablaze
Wrap one absolute value around the real and imaginary parts before squaring, and the Mandelbrot vanishes — a ship spewing flames takes its place. The most dramatic proof that a tiny change of formula opens a different world.
Best forMath-play content, hero backgrounds
createImageDataMath.absrequestAnimationFrame

<main class="stage">
<div class="mb is-demo" id="mbRoot">
<p class="mb__hint">
<span>Wrap one absolute value around the parts before squaring and the Mandelbrot vanishes — a ship spewing flames takes over, its fires born from folding orbits into the lower half-plane</span>
</p>
<div class="mb__field" role="application" aria-label="Burning Ship variant lab" tabindex="0">
<canvas class="mb__cv" id="mbCv"></canvas>
</div>
<div class="mb__bar">
<span class="mb__meta">z = |z|² + c · max iterations 128</span>
<span class="mb__meta mb__meta--dim">canvas · Math.abs · requestAnimationFrame</span>
</div>
</div>
</main>@use "../../../../site/static/demo-tokens" as *;
// 버닝쉽 변형(06). @keyframes 없음 — 캔버스 rAF(절댓값 반복 + 불꽃 램프 순환 + 미세 숨)이 만든다.
$duration: $dur-loop;
$easing: $ease-spring;
$color: $subject-orange-deep;
// ── 편 공통 심야 프랙탈 팔레트 ──
$mb-stage: #1a1726;
@include stage($mb-stage);
$mb-ink: #14111f;
$mb-set: #241d38;
$mb-text: #cfc8e8;
.mb {
// 불 팔레트 — 밤청 → 보라 → 파스텔 골드 → 복숭아 (전부 고명도·저채도 파스텔)
--mb-f0: #1f2340;
--mb-f1: #4a3a68;
--mb-f2: #ffe9ad;
--mb-f3: #efc0b5;
--mb-f4: #1f2340;
--mb-set: #{$mb-set};
display: flex; flex-direction: column; gap: $sp-2;
width: 100%; max-width: 424px;
}
.mb__hint {
display: flex; align-items: center; gap: $sp-1; margin: 0;
font-weight: 700; font-size: clamp(10px, 2.8vw, 12px); line-height: 1.35;
color: $mb-text;
}
.mb__field {
position: relative; height: 180px;
border-radius: $r-card; overflow: hidden;
background: $mb-ink;
box-shadow: inset 0 0 0 1px rgba($mb-text, .18);
}
.mb__field:focus-visible { outline: 2px solid $subject-lilac; outline-offset: 2px; }
.mb__cv { display: block; width: 100%; height: 100%; }
.mb__bar { display: flex; align-items: baseline; justify-content: space-between; gap: $sp-2; }
.mb__meta { font-size: 10px; font-weight: 500; color: rgba($mb-text, .72); }
.mb__meta--dim { font-size: 10px; }
@media (max-width: 340px) {
.mb { gap: $sp-1; }
.mb__field { height: 100px; }
.mb__meta--dim { display: none; }
}
// reduce — 발광 위상 한 장만 고정.
@media (prefers-reduced-motion: reduce) {
.mb.is-still .mb__field { cursor: default !important; }
}html, body {
margin: 0;
overflow: hidden;
}
.stage {
box-sizing: border-box;
min-height: 100vh;
display: grid;
place-items: center;
margin: 0;
background: #1a1726;
font-family: -apple-system, "Segoe UI", "Noto Sans KR", sans-serif;
padding: clamp(8px, 4vw, 24px);
}
.mb {
--mb-f0: #1f2340;
--mb-f1: #4a3a68;
--mb-f2: #ffe9ad;
--mb-f3: #efc0b5;
--mb-f4: #1f2340;
--mb-set: #241d38;
display: flex;
flex-direction: column;
gap: 8px;
width: 100%;
max-width: 424px;
}
.mb__hint {
display: flex;
align-items: center;
gap: 4px;
margin: 0;
font-weight: 700;
font-size: clamp(10px, 2.8vw, 12px);
line-height: 1.35;
color: #cfc8e8;
}
.mb__field {
position: relative;
height: 180px;
border-radius: 16px;
overflow: hidden;
background: #14111f;
box-shadow: inset 0 0 0 1px rgba(207, 200, 232, 0.18);
}
.mb__field:focus-visible {
outline: 2px solid #b9a0ff;
outline-offset: 2px;
}
.mb__cv {
display: block;
width: 100%;
height: 100%;
}
.mb__bar {
display: flex;
align-items: baseline;
justify-content: space-between;
gap: 8px;
}
.mb__meta {
font-size: 10px;
font-weight: 500;
color: rgba(207, 200, 232, 0.72);
}
.mb__meta--dim {
font-size: 10px;
}
@media (max-width: 340px) {
.mb {
gap: 4px;
}
.mb__field {
height: 100px;
}
.mb__meta--dim {
display: none;
}
}
@media (prefers-reduced-motion: reduce) {
.mb.is-still .mb__field {
cursor: default !important;
}
}// 버닝쉽 변형(06) — 식 한 줄의 힘.
// 만델브로: z = z² + c. 버닝쉽: z = (|Re z| + i|Im z|)² + c — 제곱 전에 두 성분의 절댓값.
// 절댓값이 위 반평면의 궤적을 아래로 접기 때문에 지수가 쌓이는 방향(아래)으로 "불꽃"이 뻗는다.
// 뷰포트는 표준 버닝쉽 프레임(배 본체가 보이는 -1.8~-0.7 · -0.1~-0.9, y 뒤집기).
// 움직임: 불꽃 발광 위상 순환(팔레트 순환과 유사하지만 불꽃 끝단이 위로 갈수록 밝아지는
// 램프를 얹어 "타오르는" 느낌을 만든다) + 미세 확대 숨.
(function () {
// ── 변형 상수 블록 — 아래 값 하나만 바꿔 변형을 만든다 ──
var MAXIT = 128; // 최대 반복
var POWER = 2; // 지수 — 변형 "식 바꾸기"가 2 → 3 (z³+c, 대칭 2회→3회)
// ────────────────────────────────────────────────────
var root = document.getElementById('mbRoot');
var cv = document.getElementById('mbCv');
var field = cv.parentElement;
var css = getComputedStyle(root);
function tokRGB(name) {
var s = css.getPropertyValue(name).trim();
var hx = s.length === 4
? s.charAt(1) + s.charAt(1) + s.charAt(2) + s.charAt(2) + s.charAt(3) + s.charAt(3)
: s.slice(1);
return [parseInt(hx.slice(0, 2), 16), parseInt(hx.slice(2, 4), 16), parseInt(hx.slice(4, 6), 16)];
}
// 불 팔레트 — 짙은 밤청 → 보라 → 파스텔 골드 → 복숭아 (고명도 파스텔이라 vivid 아님)
var PAL = ['--mb-f0', '--mb-f1', '--mb-f2', '--mb-f3', '--mb-f4'].map(tokRGB);
var C_SET = tokRGB('--mb-set');
var reduce = window.matchMedia('(prefers-reduced-motion: reduce)').matches;
var raf = 0, t0 = -1;
var W = 0, H = 0, IRES = 240;
var ov, octx;
// 버닝쉽 표준 뷰 — 본체(배)가 중앙, 불꽃이 아래로. y 축은 화면 좌표(위가 -)라 뒤집는다
var CX = -1.755, CY = -0.04, SPAN0 = 1.35;
function fit() {
var r = field.getBoundingClientRect();
W = Math.round(r.width); H = Math.round(r.height);
cv.width = W; cv.height = H;
ov = document.createElement('canvas');
ov.width = IRES; ov.height = Math.max(2, Math.round(IRES * H / W));
}
function render(phase, breath) {
var iw = ov.width, ih = ov.height;
var span = SPAN0 * breath;
var img = octx.createImageData(iw, ih);
var px = img.data;
var dx = span / iw, dy = span / iw;
var oy0 = CY - (ih * dy) / 2;
var k = 0;
for (var j = 0; j < ih; j++) {
var ci = oy0 + j * dy;
for (var i = 0; i < iw; i++) {
var cr = CX - span / 2 + i * dx;
var zr = 0, zi = 0, n = 0;
while (n < MAXIT && zr * zr + zi * zi <= 4) {
// ── 버닝쉽의 한 줄 — 제곱 전 절댓값 ──
var ar = Math.abs(zr), ai = Math.abs(zi);
if (POWER === 2) {
var t = ar * ar - ai * ai + cr;
zi = 2 * ar * ai + ci;
} else {
// 3차 변형 — (|z|)³: 데 무아브르 3배각
var t = ar * ar * ar - 3 * ar * ai * ai + cr;
zi = 3 * ar * ar * ai - ai * ai * ai + ci;
}
zr = t;
n++;
}
var r, g, b;
if (n >= MAXIT) {
r = C_SET[0]; g = C_SET[1]; b = C_SET[2];
} else {
// 불꽃 램프 — 화면 아래(불꽃 끝)로 갈수록 밝게. j 가 클수록 아래
var heat = (j / ih) * 0.7 + (n / MAXIT) * 0.3;
var u = heat * 3 + phase;
var seg = u - Math.floor(u / 4) * 4;
var a = PAL[Math.floor(seg) % 4], bb = PAL[(Math.floor(seg) + 1) % 4];
var f = seg - Math.floor(seg);
r = a[0] + (bb[0] - a[0]) * f;
g = a[1] + (bb[1] - a[1]) * f;
b = a[2] + (bb[2] - a[2]) * f;
}
px[k++] = r; px[k++] = g; px[k++] = b; px[k++] = 255;
}
}
octx.putImageData(img, 0, 0);
cv.getContext('2d').drawImage(ov, 0, 0, W, H);
}
function frame(now) {
if (t0 < 0) t0 = now;
var loop = ((now - t0) / 1000) % 2.0;
var t = loop / 2.0;
var phase = t * 3; // 발광 위상 — 2초에 파장 3칸
var breath = 1 + 0.045 * Math.sin(t * Math.PI * 2); // 미세 확대 숨(±4.5%)
render(phase, breath);
raf = requestAnimationFrame(frame);
}
window.addEventListener('resize', function () { fit(); render(reduce ? 0.5 : 0.5, 1); });
fit();
octx = ov.getContext('2d');
if (reduce) {
render(0.5, 1);
root.classList.add('is-still');
} else {
raf = requestAnimationFrame(frame);
}
})();// BurningShipVariant — vanilla 판(run/323/demo/06-mb-burning-ship-variant/index.html) 의 React 포트.
// 식 한 줄의 힘. 만델브로: z = z² + c. 버닝쉽: z = (|Re z| + i|Im z|)² + c — 제곱 전에 두 성분의 절댓값.
// 절댓값이 위 반평면의 궤적을 아래로 접기 때문에 지수가 쌓이는 방향(아래)으로 "불꽃"이 뻗는다.
// 뷰포트는 표준 버닝쉽 프레임(배 본체가 보이는 -1.8~-0.7 · -0.1~-0.9, y 뒤집기).
// 움직임: 불꽃 발광 위상 순환(불꽃 끝단이 위로 갈수록 밝아지는 램프를 얹어 "타오르는" 느낌)
// + 미세 확대 숨.
import { useEffect, useRef, useState } from "react";
import type { CSSProperties } from "react";
import styles from "./BurningShipVariant.module.scss";
export type BurningShipVariantProps = {
duration?: string;
easing?: string;
color?: string;
power?: number; // 지수 — 변형 "식 바꾸기"가 2 → 3 (z³+c, 대칭 2회→3회)
};
// ── 변형 상수(기본값) — vanilla 판과 동일 ──
const MAXIT = 128; // 최대 반복
const IRES = 240; // 내부 계산 해상도(가로 픽셀)
type Vars = CSSProperties & { "--duration"?: string; "--easing"?: string; "--color"?: string };
type Box<T> = { current: T };
type RGB = [number, number, number];
const FIELD_LABEL = "버닝쉽 변형 실험판";
const META_LEFT = "z = |z|² + c · 최대 반복 128";
const META_RIGHT = "canvas · Math.abs · requestAnimationFrame";
const HINT = "제곱 전에 실수·허수에 절댓값 한 줄만 씌우면 만델브로가 사라지고 불꽃을 뿜는 배가 나타납니다 — 절댓값이 궤적을 아래 반평면으로 접어 넣어 불꽃 무늬가 생깁니다";
// 버닝쉽 표준 뷰 — 본체(배)가 중앙, 불꽃이 아래로. y 축은 화면 좌표(위가 -)라 뒤집는다
const CX = -1.755, CY = -0.04, SPAN0 = 1.35;
export default function BurningShipVariant({
duration = "2s",
easing = "cubic-bezier(.2, .8, .2, 1)",
color = "#ffe9ad",
power = 2
}: BurningShipVariantProps) {
const rootRef = useRef<HTMLDivElement | null>(null);
const fieldRef = useRef<HTMLDivElement | null>(null);
const cvRef = useRef<HTMLCanvasElement | null>(null);
const ctxRef = useRef<CanvasRenderingContext2D | null>(null);
const ovRef = useRef<HTMLCanvasElement | null>(null);
const octxRef = useRef<CanvasRenderingContext2D | null>(null);
const palRef = useRef<RGB[] | null>(null);
const setRef = useRef<RGB | null>(null);
const powerRef = useRef(power) as Box<number>;
const wRef = useRef(0) as Box<number>;
const hRef = useRef(0) as Box<number>;
const rafRef = useRef(0) as Box<number>;
const [still, setStill] = useState(false);
const vars: Vars = { "--duration": duration, "--easing": easing, "--color": color };
function reduced(): boolean {
return window.matchMedia("(prefers-reduced-motion: reduce)").matches;
}
function tokRGB(root: HTMLDivElement, name: string): RGB {
const s = getComputedStyle(root).getPropertyValue(name).trim();
const hx = s.length === 4
? s.charAt(1) + s.charAt(1) + s.charAt(2) + s.charAt(2) + s.charAt(3) + s.charAt(3)
: s.slice(1);
return [parseInt(hx.slice(0, 2), 16), parseInt(hx.slice(2, 4), 16), parseInt(hx.slice(4, 6), 16)];
}
function fit(): void {
const field = fieldRef.current;
const cv = cvRef.current;
if (!field || !cv) return;
const r = field.getBoundingClientRect();
const W = Math.round(r.width), H = Math.round(r.height);
wRef.current = W; hRef.current = H;
cv.width = W; cv.height = H;
ctxRef.current = cv.getContext("2d");
const ov = document.createElement("canvas");
ov.width = IRES;
ov.height = Math.max(2, Math.round(IRES * H / W));
ovRef.current = ov;
octxRef.current = ov.getContext("2d");
}
function render(phase: number, breath: number): void {
const octx = octxRef.current;
const ov = ovRef.current;
const ctx = ctxRef.current;
const PAL = palRef.current;
const C_SET = setRef.current;
const W = wRef.current, H = hRef.current;
const POWER = powerRef.current;
if (!octx || !ov || !ctx || !PAL || !C_SET) return;
const iw = ov.width, ih = ov.height;
const span = SPAN0 * breath;
const img = octx.createImageData(iw, ih);
const px = img.data;
const dx = span / iw, dy = span / iw;
const oy0 = CY - (ih * dy) / 2;
let k = 0;
for (let j = 0; j < ih; j++) {
const ci = oy0 + j * dy;
for (let i = 0; i < iw; i++) {
const cr = CX - span / 2 + i * dx;
let zr = 0, zi = 0, n = 0;
while (n < MAXIT && zr * zr + zi * zi <= 4) {
// ── 버닝쉽의 한 줄 — 제곱 전 절댓값 ──
const ar = Math.abs(zr), ai = Math.abs(zi);
let t: number;
if (POWER === 2) {
t = ar * ar - ai * ai + cr;
zi = 2 * ar * ai + ci;
} else {
// 3차 변형 — (|z|)³: 데 무아브르 3배각
t = ar * ar * ar - 3 * ar * ai * ai + cr;
zi = 3 * ar * ar * ai - ai * ai * ai + ci;
}
zr = t;
n++;
}
let r: number, g: number, b: number;
if (n >= MAXIT) {
r = C_SET[0]; g = C_SET[1]; b = C_SET[2];
} else {
// 불꽃 램프 — 화면 아래(불꽃 끝)로 갈수록 밝게. j 가 클수록 아래
const heat = (j / ih) * 0.7 + (n / MAXIT) * 0.3;
const u = heat * 3 + phase;
const seg = u - Math.floor(u / 4) * 4;
const a = PAL[Math.floor(seg) % 4], bb = PAL[(Math.floor(seg) + 1) % 4];
const f = seg - Math.floor(seg);
r = a[0] + (bb[0] - a[0]) * f;
g = a[1] + (bb[1] - a[1]) * f;
b = a[2] + (bb[2] - a[2]) * f;
}
px[k++] = r; px[k++] = g; px[k++] = b; px[k++] = 255;
}
}
octx.putImageData(img, 0, 0);
ctx.drawImage(ov, 0, 0, W, H);
}
let t0 = -1;
function frame(now: number): void {
if (t0 < 0) t0 = now;
const loop = ((now - t0) / 1000) % 2.0;
const t = loop / 2.0;
const phase = t * 3; // 발광 위상 — 2초에 파장 3칸
const breath = 1 + 0.045 * Math.sin(t * Math.PI * 2); // 미세 확대 숨(±4.5%)
render(phase, breath);
rafRef.current = requestAnimationFrame(frame);
}
useEffect(() => {
const root = rootRef.current;
if (!root) return;
powerRef.current = power;
// 불 팔레트 — 짙은 밤청 → 보라 → 파스텔 골드 → 복숭아 (고명도 파스텔이라 vivid 아님)
palRef.current = ["--mb-f0", "--mb-f1", "--mb-f2", "--mb-f3", "--mb-f4"].map((nm) => tokRGB(root, nm));
setRef.current = tokRGB(root, "--mb-set");
fit();
function onResize(): void {
fit(); render(0.5, 1);
}
window.addEventListener("resize", onResize);
if (reduced()) {
render(0.5, 1); // reduce — 발광 위상 한 장 고정
setStill(true);
} else {
t0 = -1;
rafRef.current = requestAnimationFrame(frame);
}
return () => {
window.removeEventListener("resize", onResize);
cancelAnimationFrame(rafRef.current);
};
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [power]);
const rootCls = still ? `${styles.root} ${styles.isStill}` : styles.root;
return (
<main className={styles.stage}>
<div className={rootCls} ref={rootRef} style={vars}>
<p className={styles.hint}>
<span>{HINT}</span>
</p>
<div
className={styles.field}
ref={fieldRef}
role="application"
aria-label={FIELD_LABEL}
tabIndex={0}
>
<canvas className={styles.cv} ref={cvRef}></canvas>
</div>
<div className={styles.bar}>
<span className={styles.meta}>{META_LEFT}</span>
<span className={styles.metaDim}>{META_RIGHT}</span>
</div>
</div>
</main>
);
}06 Burning Ship variant — one absolute value turns the set into a ship ablaze — Measured area 45.881% · moving frames 23/23Original by GODRICH · SCSS and React ship in the zip · Mandelbrot Zoom, 9 Ways (Escape-Time, No Library)
The post this demo lives in
Mandelbrot Zoom, 9 Ways (Escape-Time, No Library)Iterate z = z² + c per pixel and count escapes — the Mandelbrot cardioid appears, and every zoom level hides new mini-ma See all demos in this post
If you like this effect - similar demos
Creative UI07 Sensor-angle morph — one angle value turns coral into blood vesselsSlime Mold Simulation, 9 Ways (No Library)
Creative UI02 Stripe bands — one parameter turns dots into lines9 Reaction Diffusion Simulations, No Library
Creative UI03 Cloud field — drifting fbm cloud layer9 Perlin Noise Animations, No Libraries, Pure Math