09Hero Background Scene
Combines the techniques above into one background scene that fills a full hero section.
Best forFull website hero sections
HERO_BLOB_RADIUS_PXrenderFieldhslToRgb

<main class="stage">
<div class="pv is-demo" id="pvRoot">
<canvas class="pv__canvas" id="pvCanvas" width="480" height="300"></canvas>
<p class="pv__caption">A hero background scene that merges the sine field and color blobs into one</p>
</div>
</main>@use "../../../../site/static/demo-tokens" as *;
@include stage($stage-ink);
.pv {
position: relative;
width: min(92vw, calc(160vh - 12.8vw));
aspect-ratio: 480 / 300;
margin: 0 auto;
border-radius: $r-card;
overflow: hidden;
box-shadow: $shadow-raised;
}
.pv__canvas {
display: block;
width: 100%;
height: 100%;
}
.pv__caption {
position: absolute;
left: $sp-3;
bottom: $sp-3;
max-width: 72%;
margin: 0;
padding: $sp-1 $sp-3;
border-radius: $r-pill;
background: rgba(255, 247, 230, .85);
color: $subject-ink;
font-weight: 500;
font-size: 12px;
line-height: 1.4;
pointer-events: none;
}
@media (max-width: 340px) {
.pv__caption { font-size: 10px; padding: $sp-1 $sp-2; }
}
@media (prefers-reduced-motion: reduce) {
.pv { cursor: default; }
}html, body {
margin: 0;
overflow: hidden;
}
.stage {
box-sizing: border-box;
min-height: 100vh;
display: grid;
place-items: center;
margin: 0;
background: #17141a;
font-family: -apple-system, "Segoe UI", "Noto Sans KR", sans-serif;
padding: clamp(8px, 4vw, 24px);
}
.pv {
position: relative;
width: min(92vw, 160vh - 12.8vw);
aspect-ratio: 480/300;
margin: 0 auto;
border-radius: 16px;
overflow: hidden;
box-shadow: 0 14px 24px rgba(23, 20, 26, 0.32);
}
.pv__canvas {
display: block;
width: 100%;
height: 100%;
}
.pv__caption {
position: absolute;
left: 12px;
bottom: 12px;
max-width: 72%;
margin: 0;
padding: 4px 12px;
border-radius: 999px;
background: rgba(255, 247, 230, 0.85);
color: #17141a;
font-weight: 500;
font-size: 12px;
line-height: 1.4;
pointer-events: none;
}
@media (max-width: 340px) {
.pv__caption {
font-size: 10px;
padding: 4px 8px;
}
}
@media (prefers-reduced-motion: reduce) {
.pv {
cursor: default;
}
}(function () {
// 합성: 01(plasma-sine-field-classic) 의 사인파 3개 합 hue 필드를 바탕색으로 깔고,
// 05(plasma-metaball-color-blend) 의 덩어리 2개를 그 위에 가중 혼합해 얹은 히어로 장면.
// 01 의 renderField 공식과 05 의 metaball weight(w = R²/(d²+R²×2)) 공식을 그대로 가져와
// 한 프레임 안에서 순서대로 섞는다(바탕 → 덩어리 오버레이).
var root = document.getElementById('pvRoot');
var canvas = document.getElementById('pvCanvas');
var ctx = canvas.getContext('2d');
var wrap = canvas.parentElement;
var CALC_W = 160, CALC_H = 100;
var LOOP_MS = 2000;
// --- 01 sine-field 상수 ---
var PLASMA_SINE_FREQ_X = 0.055;
var PLASMA_SINE_FREQ_Y = 0.07;
var PLASMA_SINE_FREQ_R = 0.09;
var PLASMA_TIME_SPEED = Math.PI * 2 / LOOP_MS;
// --- 05 metaball 상수 ---
var HERO_BLOB_RADIUS_PX = 46;
var DRIFT_AMP = 12;
function seedRand(seed) {
var s = seed >>> 0;
return function () {
s = (s * 1664525 + 1013904223) >>> 0;
return s / 4294967296;
};
}
function hslToRgb(h, s, l) {
h = ((h % 360) + 360) % 360;
var c = (1 - Math.abs(2 * l - 1)) * s;
var x = c * (1 - Math.abs((h / 60) % 2 - 1));
var m = l - c / 2;
var r, g, b;
if (h < 60) { r = c; g = x; b = 0; }
else if (h < 120) { r = x; g = c; b = 0; }
else if (h < 180) { r = 0; g = c; b = x; }
else if (h < 240) { r = 0; g = x; b = c; }
else if (h < 300) { r = x; g = 0; b = c; }
else { r = c; g = 0; b = x; }
return [(r + m) * 255, (g + m) * 255, (b + m) * 255];
}
var heroRand = seedRand(417091);
var blobs = [190, 40].map(function (hue) {
return {
hue: hue,
rgb: hslToRgb(hue, 0.7, 0.55),
bx: heroRand() * 0.5 + 0.25,
by: heroRand() * 0.5 + 0.25,
phase: heroRand() * Math.PI * 2
};
});
var off = document.createElement('canvas');
off.width = CALC_W; off.height = CALC_H;
var octx = off.getContext('2d');
var offImg = octx.createImageData(CALC_W, CALC_H);
var offBuf = offImg.data;
function renderField(t) {
var tt = t * PLASMA_TIME_SPEED;
var bcx = [], bcy = [];
for (var bi = 0; bi < blobs.length; bi += 1) {
var b = blobs[bi];
bcx[bi] = b.bx * CALC_W + Math.sin(tt * 0.8 + b.phase) * DRIFT_AMP;
bcy[bi] = b.by * CALC_H + Math.cos(tt * 0.6 + b.phase) * DRIFT_AMP;
}
var idx = 0;
for (var y = 0; y < CALC_H; y += 1) {
for (var x = 0; x < CALC_W; x += 1) {
var v = Math.sin(x * PLASMA_SINE_FREQ_X + tt) +
Math.sin(y * PLASMA_SINE_FREQ_Y + tt * 1.3) +
Math.sin((x + y) * PLASMA_SINE_FREQ_R * 0.5 + tt * 0.7) +
Math.sin(Math.sqrt((x - 80) * (x - 80) + (y - 50) * (y - 50)) * PLASMA_SINE_FREQ_R - tt);
var baseHue = (v / 4) * 180 + 200 + tt * 8;
var baseRgb = hslToRgb(baseHue, 0.55, 0.4);
var sr = baseRgb[0], sg = baseRgb[1], sb = baseRgb[2], sw = 1;
for (var k = 0; k < blobs.length; k += 1) {
var dx = x - bcx[k], dy = y - bcy[k];
var d2 = dx * dx + dy * dy;
var R2 = HERO_BLOB_RADIUS_PX * HERO_BLOB_RADIUS_PX;
var w = R2 / (d2 + R2 * 2);
w = w * w * 3.2;
sr += blobs[k].rgb[0] * w;
sg += blobs[k].rgb[1] * w;
sb += blobs[k].rgb[2] * w;
sw += w;
}
offBuf[idx] = sr / sw; offBuf[idx + 1] = sg / sw; offBuf[idx + 2] = sb / sw; offBuf[idx + 3] = 255;
idx += 4;
}
}
}
var cw = 480, ch = 300;
function fit() {
var r = wrap.getBoundingClientRect();
cw = Math.max(1, Math.round(r.width));
ch = Math.max(1, Math.round(r.height));
canvas.width = cw; canvas.height = ch;
draw(lastElapsed);
}
var lastElapsed = 0;
function draw(elapsed) {
lastElapsed = elapsed;
renderField(elapsed);
octx.putImageData(offImg, 0, 0);
ctx.imageSmoothingEnabled = false;
ctx.clearRect(0, 0, cw, ch);
ctx.drawImage(off, 0, 0, CALC_W, CALC_H, 0, 0, cw, ch);
}
var reduce = window.matchMedia('(prefers-reduced-motion: reduce)').matches;
var playing = !reduce;
var elapsed = reduce ? LOOP_MS * 0.5 : 0;
if (reduce) { root.classList.remove('is-demo'); }
var lastTs = null;
function tick(ts) {
if (lastTs === null) lastTs = ts;
var dt = ts - lastTs;
lastTs = ts;
if (playing) {
elapsed += dt;
if (elapsed >= LOOP_MS) elapsed -= LOOP_MS;
}
draw(elapsed);
requestAnimationFrame(tick);
}
fit();
window.addEventListener('resize', fit);
draw(elapsed);
requestAnimationFrame(tick);
})();import { useEffect, useRef } from "react";
import styles from "./PlasmaHeroBackgroundScene.module.scss";
// 합성: 01(plasma-sine-field-classic) 의 사인파 3개 합 hue 필드를 바탕색으로 깔고,
// 05(plasma-metaball-color-blend) 의 덩어리 2개를 그 위에 가중 혼합해 얹은 히어로 장면.
// 01 의 renderField 공식과 05 의 metaball weight 공식을 그대로 가져와
// 한 프레임 안에서 순서대로 섞는다(바탕 -> 덩어리 오버레이).
export default function PlasmaHeroBackgroundScene() {
const rootRef = useRef<HTMLDivElement>(null);
const canvasRef = useRef<HTMLCanvasElement>(null);
useEffect(() => {
const root = rootRef.current;
const canvas = canvasRef.current;
if (!root || !canvas) return;
const ctx = canvas.getContext("2d");
if (!ctx) return;
const wrap = canvas.parentElement as HTMLElement;
const CALC_W = 160, CALC_H = 100;
const LOOP_MS = 2000;
// --- 01 sine-field 상수 ---
const PLASMA_SINE_FREQ_X = 0.055;
const PLASMA_SINE_FREQ_Y = 0.07;
const PLASMA_SINE_FREQ_R = 0.09;
const PLASMA_TIME_SPEED = (Math.PI * 2) / LOOP_MS;
// --- 05 metaball 상수 ---
const HERO_BLOB_RADIUS_PX = 46;
const DRIFT_AMP = 12;
function seedRand(seed: number) {
let s = seed >>> 0;
return function () { s = (s * 1664525 + 1013904223) >>> 0; return s / 4294967296; };
}
function hslToRgb(h: number, s: number, l: number): [number, number, number] {
h = ((h % 360) + 360) % 360;
const c = (1 - Math.abs(2 * l - 1)) * s;
const x = c * (1 - Math.abs(((h / 60) % 2) - 1));
const m = l - c / 2;
let r = 0, g = 0, b = 0;
if (h < 60) { r = c; g = x; b = 0; }
else if (h < 120) { r = x; g = c; b = 0; }
else if (h < 180) { r = 0; g = c; b = x; }
else if (h < 240) { r = 0; g = x; b = c; }
else if (h < 300) { r = x; g = 0; b = c; }
else { r = c; g = 0; b = x; }
return [(r + m) * 255, (g + m) * 255, (b + m) * 255];
}
type Blob = { hue: number; rgb: [number, number, number]; bx: number; by: number; phase: number };
const heroRand = seedRand(417091);
const blobs: Blob[] = [190, 40].map((hue) => ({
hue,
rgb: hslToRgb(hue, 0.7, 0.55),
bx: heroRand() * 0.5 + 0.25,
by: heroRand() * 0.5 + 0.25,
phase: heroRand() * Math.PI * 2,
}));
const off = document.createElement("canvas");
off.width = CALC_W; off.height = CALC_H;
const octx = off.getContext("2d") as CanvasRenderingContext2D;
const offImg = octx.createImageData(CALC_W, CALC_H);
const offBuf = offImg.data;
function renderField(t: number) {
const tt = t * PLASMA_TIME_SPEED;
const bcx: number[] = [], bcy: number[] = [];
for (let bi = 0; bi < blobs.length; bi += 1) {
const b = blobs[bi];
bcx[bi] = b.bx * CALC_W + Math.sin(tt * 0.8 + b.phase) * DRIFT_AMP;
bcy[bi] = b.by * CALC_H + Math.cos(tt * 0.6 + b.phase) * DRIFT_AMP;
}
let idx = 0;
for (let y = 0; y < CALC_H; y += 1) {
for (let x = 0; x < CALC_W; x += 1) {
const v = Math.sin(x * PLASMA_SINE_FREQ_X + tt) +
Math.sin(y * PLASMA_SINE_FREQ_Y + tt * 1.3) +
Math.sin((x + y) * PLASMA_SINE_FREQ_R * 0.5 + tt * 0.7) +
Math.sin(Math.sqrt((x - 80) * (x - 80) + (y - 50) * (y - 50)) * PLASMA_SINE_FREQ_R - tt);
const baseHue = (v / 4) * 180 + 200 + tt * 8;
const baseRgb = hslToRgb(baseHue, 0.55, 0.4);
let sr = baseRgb[0], sg = baseRgb[1], sb = baseRgb[2], sw = 1;
for (let k = 0; k < blobs.length; k += 1) {
const dx = x - bcx[k], dy = y - bcy[k];
const d2 = dx * dx + dy * dy;
const R2 = HERO_BLOB_RADIUS_PX * HERO_BLOB_RADIUS_PX;
let w = R2 / (d2 + R2 * 2);
w = w * w * 3.2;
sr += blobs[k].rgb[0] * w;
sg += blobs[k].rgb[1] * w;
sb += blobs[k].rgb[2] * w;
sw += w;
}
offBuf[idx] = sr / sw; offBuf[idx + 1] = sg / sw; offBuf[idx + 2] = sb / sw; offBuf[idx + 3] = 255;
idx += 4;
}
}
}
let cw = 480, ch = 300;
function fit() {
const r = wrap.getBoundingClientRect();
cw = Math.max(1, Math.round(r.width));
ch = Math.max(1, Math.round(r.height));
canvas!.width = cw; canvas!.height = ch;
draw(lastElapsed);
}
let lastElapsed = 0;
function draw(elapsed: number) {
lastElapsed = elapsed;
renderField(elapsed);
octx.putImageData(offImg, 0, 0);
ctx!.imageSmoothingEnabled = false;
ctx!.clearRect(0, 0, cw, ch);
ctx!.drawImage(off, 0, 0, CALC_W, CALC_H, 0, 0, cw, ch);
}
const reduce = window.matchMedia("(prefers-reduced-motion: reduce)").matches;
let playing = !reduce;
let elapsed = reduce ? LOOP_MS * 0.5 : 0;
if (reduce) { root.classList.remove("is-demo"); }
let lastTs: number | null = null;
let raf = 0;
function tick(ts: number) {
if (lastTs === null) lastTs = ts;
const dt = ts - lastTs;
lastTs = ts;
if (playing) {
elapsed += dt;
if (elapsed >= LOOP_MS) elapsed -= LOOP_MS;
}
draw(elapsed);
raf = requestAnimationFrame(tick);
}
fit();
window.addEventListener("resize", fit);
draw(elapsed);
raf = requestAnimationFrame(tick);
return () => {
cancelAnimationFrame(raf);
window.removeEventListener("resize", fit);
};
}, []);
return (
<main className={styles.stage}>
<div className={`${styles.pv} is-demo`} ref={rootRef}>
<canvas className={styles.pv__canvas} ref={canvasRef} width={480} height={300} />
<p className={styles.pv__caption}>사인 필드와 색 덩어리를 하나로 합친 히어로 배경 장면</p>
</div>
</main>
);
}09 Hero Background Scene — Measured area 72.383% · moving frames 23/23Original by GODRICH · SCSS and React ship in the zip · Rainbow Gradient Background CSS: 9 Patterns
The post this demo lives in
Rainbow Gradient Background CSS: 9 PatternsA rainbow gradient background css, explained: Light, you start out with no color. Item 1 layers three sine waves onto yo See all demos in this post
If you like this effect - similar demos
Creative UI06 Layered starfield background with parallax3D Globe Website: 9 Canvas Orbit Scenes
Creative UI09 Fractal hero scene — a front-door stage layered with type and starlightMandelbrot Zoom, 9 Ways (Escape-Time, No Library)
Creative UI09 Butterfly hero scene — a front-door stage layered with type and particlesLorenz Attractor: 9 Butterfly Chaos Demos