04회전 대칭 만다라
획 하나를 그린 뒤 중심을 기준으로 열두 번 돌려 붙여 대칭 무늬를 만듭니다.
쓰임명상·요가 앱의 시작 화면, 이벤트 초대장의 장식 원
transform-originrotatestroke-linejoin

<main class="stage">
<div class="md is-demo" id="root">
<svg class="md__art" id="art" viewBox="0 0 240 150" role="img" data-label="획 하나를 열두 번 돌려 만든 대칭 무늬, 시드 {n}"></svg>
<div class="md__bar">
<p class="md__seed">
<svg xmlns="http://www.w3.org/2000/svg" class="md__ic" viewBox="0 0 256 256" aria-hidden="true"><g fill="currentColor"><path d="M216 64v128a24 24 0 0 1-24 24H64a24 24 0 0 1-24-24V64a24 24 0 0 1 24-24h128a24 24 0 0 1 24 24" opacity=".2"/><path d="M192 32H64a32 32 0 0 0-32 32v128a32 32 0 0 0 32 32h128a32 32 0 0 0 32-32V64a32 32 0 0 0-32-32m16 160a16 16 0 0 1-16 16H64a16 16 0 0 1-16-16V64a16 16 0 0 1 16-16h128a16 16 0 0 1 16 16ZM104 92a12 12 0 1 1-12-12a12 12 0 0 1 12 12m72 0a12 12 0 1 1-12-12a12 12 0 0 1 12 12m-72 72a12 12 0 1 1-12-12a12 12 0 0 1 12 12m36-36a12 12 0 1 1-12-12a12 12 0 0 1 12 12m36 36a12 12 0 1 1-12-12a12 12 0 0 1 12 12"/></g></svg>
시드 <b id="num">7</b>
</p>
<button class="md__btn" type="button" id="again">
<svg xmlns="http://www.w3.org/2000/svg" class="md__ic" viewBox="0 0 256 256" aria-hidden="true"><g fill="currentColor"><path d="M107.14 98.8L128 128l-20.86 29.2A64 64 0 0 1 55.06 184H32V72h23.06a64 64 0 0 1 52.08 26.8m93.8-26.8a64 64 0 0 0-52.08 26.8L128 128l20.86 29.2a64 64 0 0 0 52.08 26.8H232V72Z" opacity=".2"/><path d="M237.66 178.34a8 8 0 0 1 0 11.32l-24 24a8 8 0 0 1-11.32-11.32L212.69 192h-11.75a72.12 72.12 0 0 1-58.59-30.15l-41.72-58.4A56.1 56.1 0 0 0 55.06 80H32a8 8 0 0 1 0-16h23.06a72.12 72.12 0 0 1 58.59 30.15l41.72 58.4A56.1 56.1 0 0 0 200.94 176h11.75l-10.35-10.34a8 8 0 0 1 11.32-11.32ZM143 107a8 8 0 0 0 11.16-1.86l1.2-1.67A56.1 56.1 0 0 1 200.94 80h11.75l-10.35 10.34a8 8 0 0 0 11.32 11.32l24-24a8 8 0 0 0 0-11.32l-24-24a8 8 0 0 0-11.32 11.32L212.69 64h-11.75a72.12 72.12 0 0 0-58.59 30.15l-1.2 1.67A8 8 0 0 0 143 107m-30 42a8 8 0 0 0-11.16 1.86l-1.2 1.67A56.1 56.1 0 0 1 55.06 176H32a8 8 0 0 0 0 16h23.06a72.12 72.12 0 0 0 58.59-30.15l1.2-1.67A8 8 0 0 0 113 149"/></g></svg>
<span class="md__label">다시 생성</span>
</button>
<button class="md__btn" type="button" id="copy" data-done="복사됨">
<svg xmlns="http://www.w3.org/2000/svg" class="md__ic" viewBox="0 0 256 256" aria-hidden="true"><g fill="currentColor"><path d="M216 40v128h-48V88H88V40Z" opacity=".2"/><path d="M216 32H88a8 8 0 0 0-8 8v40H40a8 8 0 0 0-8 8v128a8 8 0 0 0 8 8h128a8 8 0 0 0 8-8v-40h40a8 8 0 0 0 8-8V40a8 8 0 0 0-8-8m-56 176H48V96h112Zm48-48h-32V88a8 8 0 0 0-8-8H96V48h112Z"/></g></svg>
<span class="md__label">SVG 복사</span>
</button>
</div>
</div>
</main>@use "../../../../site/static/demo-tokens" as *;
// 회전 대칭 만다라 — 난수는 "획 하나"에만 쓰고 나머지 열한 개는 그 획을 30도씩 돌린 복사본이다.
// 미리보기 루프는 겹(ring)이 서로 반대로 조금씩 돌며 숨쉬는 것이라 시작과 끝 상태가 같다 —
// 사라졌다 나타나지 않으니 한 바퀴 끝에서 튀지 않고 poster 에도 늘 무늬가 다 차 있다.
$duration: $dur-loop;
$easing: $ease-spring;
$color: $subject-ink;
@include stage($stage-yellow);
.md { display: grid; justify-items: center; gap: $sp-3; width: 100%; }
.md__art { display: block; width: clamp(176px, 60vw, 320px); height: auto; }
// 겹의 회전 중심은 무늬의 중심이어야 한다. fill-box 는 그 겹의 경계 상자를 기준으로 잡는데
// 12겹 회전 대칭이라 경계 상자의 한가운데가 곧 만다라의 중심이다
.md__ring {
transform-box: fill-box;
transform-origin: 50% 50%;
fill: none;
stroke-linejoin: round;
stroke-linecap: round;
}
.md__ring--a { stroke: $color; stroke-width: 1.6; }
.md__ring--b { stroke: $subject-blue; stroke-width: 2.4; }
.md__eye { fill: $color; }
.md__bar { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: $sp-2; }
.md__seed {
margin: 0;
display: inline-flex; align-items: center; gap: $sp-1;
color: rgba(23, 20, 26, .78);
font-weight: 700; font-size: clamp(9px, 2.4vw, 11px);
}
.md__btn {
display: inline-flex; align-items: center; gap: $sp-1;
border: 0; border-radius: $r-pill;
padding: $sp-1 $sp-3;
background: $subject-ink; color: $subject-cream;
font-family: inherit; font-weight: 700; font-size: clamp(9px, 2.4vw, 11px);
cursor: pointer;
}
.md__btn:focus-visible { outline: 3px solid $subject-blue; outline-offset: 2px; }
.md__ic { width: 12px; height: 12px; flex: none; }
// ── 미리보기 루프: 겹마다 조금씩 다른 각도로 돌았다 제자리로 돌아온다
.md.is-demo .md__ring {
animation-name: mdBreathe;
animation-duration: $duration;
animation-timing-function: $easing;
animation-iteration-count: infinite;
animation-fill-mode: backwards;
animation-delay: calc(var(--i) * -260ms); // 음수 지연이라 첫 프레임부터 겹들이 서로 어긋나 있다
}
.md.is-demo .md__ring--b { animation-direction: reverse; }
// 사람이 「다시 생성」을 누르면 새 시드의 무늬가 한 겹씩 펼쳐진다
.md.is-draw .md__ring {
animation-name: mdOpen;
animation-duration: $dur-enter;
animation-timing-function: $ease-pop;
animation-iteration-count: 1;
animation-fill-mode: backwards;
animation-delay: calc(var(--i) * 70ms);
}
@keyframes mdBreathe {
0% { transform: rotate(0deg) scale(1); }
32% { transform: rotate(10deg) scale(1.07); }
66% { transform: rotate(-8deg) scale(.94); }
100% { transform: rotate(0deg) scale(1); }
}
@keyframes mdOpen {
from { transform: rotate(-24deg) scale(.4); opacity: 0; }
to { transform: rotate(0deg) scale(1); opacity: 1; }
}
@media (max-width: 340px) {
.md { gap: $sp-2; }
.md__ic { width: 10px; height: 10px; }
}
@media (prefers-reduced-motion: reduce) {
.md.is-demo .md__ring,
.md.is-draw .md__ring { animation: none !important; transform: rotate(0deg) scale(1) !important; }
}html, body {
margin: 0;
overflow: hidden;
}
.stage {
box-sizing: border-box;
min-height: 100vh;
display: grid;
place-items: center;
margin: 0;
background: #ffd23f;
font-family: -apple-system, "Segoe UI", "Noto Sans KR", sans-serif;
padding: clamp(8px, 4vw, 24px);
}
.md {
display: grid;
justify-items: center;
gap: 12px;
width: 100%;
}
.md__art {
display: block;
width: clamp(176px, 60vw, 320px);
height: auto;
}
.md__ring {
transform-box: fill-box;
transform-origin: 50% 50%;
fill: none;
stroke-linejoin: round;
stroke-linecap: round;
}
.md__ring--a {
stroke: #17141a;
stroke-width: 1.6;
}
.md__ring--b {
stroke: #2f6df6;
stroke-width: 2.4;
}
.md__eye {
fill: #17141a;
}
.md__bar {
display: flex;
flex-wrap: wrap;
align-items: center;
justify-content: center;
gap: 8px;
}
.md__seed {
margin: 0;
display: inline-flex;
align-items: center;
gap: 4px;
color: rgba(23, 20, 26, 0.78);
font-weight: 700;
font-size: clamp(9px, 2.4vw, 11px);
}
.md__btn {
display: inline-flex;
align-items: center;
gap: 4px;
border: 0;
border-radius: 999px;
padding: 4px 12px;
background: #17141a;
color: #fff7e6;
font-family: inherit;
font-weight: 700;
font-size: clamp(9px, 2.4vw, 11px);
cursor: pointer;
}
.md__btn:focus-visible {
outline: 3px solid #2f6df6;
outline-offset: 2px;
}
.md__ic {
width: 12px;
height: 12px;
flex: none;
}
.md.is-demo .md__ring {
animation-name: mdBreathe;
animation-duration: 2s;
animation-timing-function: cubic-bezier(0.2, 0.8, 0.2, 1);
animation-iteration-count: infinite;
animation-fill-mode: backwards;
animation-delay: calc(var(--i) * -260ms);
}
.md.is-demo .md__ring--b {
animation-direction: reverse;
}
.md.is-draw .md__ring {
animation-name: mdOpen;
animation-duration: 600ms;
animation-timing-function: cubic-bezier(0.2, 1.4, 0.4, 1);
animation-iteration-count: 1;
animation-fill-mode: backwards;
animation-delay: calc(var(--i) * 70ms);
}
@keyframes mdBreathe {
0% {
transform: rotate(0deg) scale(1);
}
32% {
transform: rotate(10deg) scale(1.07);
}
66% {
transform: rotate(-8deg) scale(0.94);
}
100% {
transform: rotate(0deg) scale(1);
}
}
@keyframes mdOpen {
from {
transform: rotate(-24deg) scale(0.4);
opacity: 0;
}
to {
transform: rotate(0deg) scale(1);
opacity: 1;
}
}
@media (max-width: 340px) {
.md {
gap: 8px;
}
.md__ic {
width: 10px;
height: 10px;
}
}
@media (prefers-reduced-motion: reduce) {
.md.is-demo .md__ring,
.md.is-draw .md__ring {
animation: none !important;
transform: rotate(0deg) scale(1) !important;
}
}var root = document.getElementById('root');
var art = document.getElementById('art');
var num = document.getElementById('num');
var CX = 120, CY = 75, ARMS = 12, RINGS = 3;
var seed = 7;
// mulberry32 — 32비트 정수 시드 하나로 언제나 같은 난수열을 돌려준다. 재현 가능한 생성의 뿌리
function mulberry32(a) {
return function () {
a = a + 0x6D2B79F5 | 0;
var t = Math.imul(a ^ a >>> 15, 1 | a);
t = t + Math.imul(t ^ t >>> 7, 61 | t) ^ t;
return ((t ^ t >>> 14) >>> 0) / 4294967296;
};
}
// 중심에서 위로 뻗는 획 하나. 이 획 하나만 난수로 정하고 나머지는 전부 이것을 돌려 쓴다
function stroke(rand, reach) {
var r1 = reach * (0.3 + rand() * 0.14), r2 = reach * (0.62 + rand() * 0.16), r3 = reach;
var w1 = 4 + rand() * 12, w2 = 2 + rand() * 14;
return 'M0 0C' + w1.toFixed(1) + ' ' + (-r1).toFixed(1) + ' ' + w2.toFixed(1) + ' ' + (-r2).toFixed(1) +
' 0 ' + (-r3).toFixed(1) + 'C' + (-w2).toFixed(1) + ' ' + (-r2).toFixed(1) + ' ' +
(-w1).toFixed(1) + ' ' + (-r1).toFixed(1) + ' 0 0Z';
}
function build() {
var rand = mulberry32(seed), parts = [], ring, arm;
for (ring = 0; ring < RINGS; ring++) {
var d = stroke(rand, 62 - ring * 17), inner = '';
for (arm = 0; arm < ARMS; arm++) {
// 획 하나를 30도씩 돌려 붙인다 — 회전 대칭은 난수를 한 번만 쓰고도 무늬가 되는 가장 싼 방법
inner += '<path transform="translate(' + CX + ' ' + CY + ') rotate(' + (arm * 360 / ARMS) + ')" d="' + d + '"/>';
}
parts.push('<g class="md__ring md__ring--' + (ring % 2 ? 'b' : 'a') + '" style="--i:' + ring + '">' + inner + '</g>');
}
parts.push('<circle class="md__eye" cx="' + CX + '" cy="' + CY + '" r="6"/>');
art.innerHTML = parts.join('');
art.setAttribute('aria-label', art.getAttribute('data-label').replace('{n}', seed));
num.textContent = seed;
}
document.getElementById('again').addEventListener('click', function () {
seed = (seed * 7 + 13) % 991 + 1;
build();
root.classList.remove('is-demo');
root.classList.remove('is-draw');
void art.getBoundingClientRect().width; // 한 번 읽어 리플로를 일으켜야 같은 애니메이션이 처음부터 다시 돈다
root.classList.add('is-draw');
});
var copyBtn = document.getElementById('copy');
copyBtn.addEventListener('click', function () {
var label = copyBtn.querySelector('.md__label');
var before = label.textContent;
if (navigator.clipboard && navigator.clipboard.writeText) {
navigator.clipboard.writeText(art.outerHTML).catch(function () {});
}
label.textContent = copyBtn.getAttribute('data-done');
setTimeout(function () { label.textContent = before; }, 1200);
});
build();// MandalaSymmetry — vanilla 판(run/293/demo/04-generative-mandala-symmetry/index.html) 의 React 포트.
// 난수는 "획 하나"에만 쓰고 나머지 열한 개는 그 획을 30도씩 돌린 복사본이다. 획 생성은 JS, 연출은 CSS.
// 시드·겹 수·팔 수·획의 반지름 비율은 vanilla 와 같은 값이다.
import { useMemo, useRef, useState } from "react";
import type { CSSProperties } from "react";
import styles from "./MandalaSymmetry.module.scss";
export type MandalaSymmetryProps = {
duration?: number;
easing?: string;
color?: string;
label?: string;
seedText?: string;
regenerateText?: string;
copyText?: string;
copiedText?: string;
};
type Vars = CSSProperties & { "--duration"?: string; "--easing"?: string; "--color"?: string };
// useRef 는 T | null 을 돌려준다. 처음부터 값이 있고 절대 비지 않는 상자는 이렇게 좁혀 쓴다
type Box<T> = { current: T };
type Ring = { i: number; tone: string; d: string };
const CX = 120;
const CY = 75;
const ARMS = 12;
const RINGS = 3;
// 팔의 각도는 시드와 무관한 상수다 — 30도씩 열두 번
const ANGLES: number[] = [];
for (let arm = 0; arm < ARMS; arm++) { ANGLES.push(arm * 360 / ARMS); }
// mulberry32 — 32비트 정수 시드 하나로 언제나 같은 난수열을 돌려준다. 재현 가능한 생성의 뿌리
function mulberry32(a: number): () => number {
return function (): number {
a = a + 0x6D2B79F5 | 0;
let t = Math.imul(a ^ a >>> 15, 1 | a);
t = t + Math.imul(t ^ t >>> 7, 61 | t) ^ t;
return ((t ^ t >>> 14) >>> 0) / 4294967296;
};
}
// 중심에서 위로 뻗는 획 하나. 이 획 하나만 난수로 정하고 나머지는 전부 이것을 돌려 쓴다
function stroke(rand: () => number, reach: number): string {
const r1 = reach * (0.3 + rand() * 0.14);
const r2 = reach * (0.62 + rand() * 0.16);
const r3 = reach;
const w1 = 4 + rand() * 12;
const w2 = 2 + rand() * 14;
return "M0 0C" + w1.toFixed(1) + " " + (-r1).toFixed(1) + " " + w2.toFixed(1) + " " + (-r2).toFixed(1) +
" 0 " + (-r3).toFixed(1) + "C" + (-w2).toFixed(1) + " " + (-r2).toFixed(1) + " " +
(-w1).toFixed(1) + " " + (-r1).toFixed(1) + " 0 0Z";
}
export default function MandalaSymmetry({
duration = 2000,
easing = "cubic-bezier(.2, .8, .2, 1)",
color = "#17141a",
label = "A symmetric figure made by turning one stroke twelve times, seed {n}",
seedText = "Seed",
regenerateText = "Regenerate",
copyText = "Copy SVG",
copiedText = "Copied",
}: MandalaSymmetryProps) {
const artRef = useRef<SVGSVGElement | null>(null);
const timerRef = useRef<number>(0) as Box<number>;
const [seed, setSeed] = useState(7);
const [mode, setMode] = useState("demo");
const [copyLabel, setCopyLabel] = useState(copyText);
const vars: Vars = { "--duration": `${duration}ms`, "--easing": easing, "--color": color };
// 시드가 바뀔 때만 다시 계산한다 — 겹마다 난수를 이어서 쓰므로 겹 순서가 곧 난수 소비 순서다
const rings = useMemo(() => {
const rand = mulberry32(seed);
const out: Ring[] = [];
for (let ring = 0; ring < RINGS; ring++) {
out.push({ i: ring, tone: ring % 2 ? "ringB" : "ringA", d: stroke(rand, 62 - ring * 17) });
}
return out;
}, [seed]);
function regenerate(): void {
setSeed((prev: number) => (prev * 7 + 13) % 991 + 1);
setMode("draw");
}
function copySvg(): void {
const art = artRef.current;
if (!art) { return; }
if (navigator.clipboard && navigator.clipboard.writeText) {
navigator.clipboard.writeText(art.outerHTML).catch(function () {});
}
setCopyLabel(copiedText);
clearTimeout(timerRef.current);
timerRef.current = window.setTimeout(() => setCopyLabel(copyText), 1200);
}
const rootClass = `${styles.md} ${mode === "demo" ? styles.isDemo : styles.isDraw}`;
return (
<div className={rootClass} style={vars}>
<svg
ref={artRef}
className={styles.art}
viewBox="0 0 240 150"
role="img"
aria-label={label.replace("{n}", String(seed))}
>
{rings.map((r: Ring) => (
<g
key={r.i}
className={`${styles.ring} ${styles[r.tone]}`}
style={{ "--i": r.i } as CSSProperties}
>
{ANGLES.map((deg: number, k: number) => (
<path key={k} transform={`translate(${CX} ${CY}) rotate(${deg})`} d={r.d} />
))}
</g>
))}
<circle className={styles.eye} cx={CX} cy={CY} r={6} />
</svg>
<div className={styles.bar}>
<p className={styles.seed}>{seedText} <b>{seed}</b></p>
<button className={styles.btn} type="button" onClick={regenerate}>{regenerateText}</button>
<button className={styles.btn} type="button" onClick={copySvg}>{copyLabel}</button>
</div>
</div>
);
}04 회전 대칭 만다라 — 측정 누적면적 11.881% · 움직인 프레임 23/23GODRICH 원작 · zip 에 SCSS·React 포함 · CSS 배경 패턴 9종 — 시드 하나로 다시 그리기
이 데모가 속한 글
CSS 배경 패턴 9종 — 시드 하나로 다시 그리기css 배경 패턴을 이미지 파일로 깔면 화면마다 같은 그림이 나옵니다. 여기 아홉 개는 숫자 하나(시드)를 넣으면 그 자리에서 무늬를 새로 계산해 SVG 로 뱉고, 같은 숫자를 다시 넣으면 똑같은 그림이 돌아옵니다. 이 글의 데모 전부 보기


