릴스에서 본 그 트리예요. 아래 코드 한 장이 전부예요. 글자 수천 개가 모여 트리가 되고, 뒤로는 서울의 밤(남산타워 · 아파트 불빛 · 붕어빵 포장마차)이 같이 그려져요. 화면 아래에서 코드가 쳐지는 만큼 위 트리가 자라요.
코드는 제가 한 줄씩 짠 게 아니라, 클로드에게 말로 시켜서 만든 파일이에요(바이브코딩).
1. 이렇게 쓰세요
- 맨 아래 「4. 코드 전체」 상자를 통째로 복사해요.
- 둘 중 편한 길로 열어요.
- 컴퓨터: 메모장(맥은 텍스트 편집기)에 붙여 넣고
트리.html이라는 이름으로 저장 → 그 파일을 더블클릭하면 브라우저에서 열려요. - 클로드: 대화창에 붙여 넣고 「이 파일 그대로 아티팩트로 실행해 줘」라고 하면 바로 보여 줘요.
- 컴퓨터: 메모장(맥은 텍스트 편집기)에 붙여 넣고
- 화면을 누르면 처음부터 다시 그려요.
2. 내 트리로 바꾸기
- 받는 사람 이름: 맨 위
const 받는사람 = "";의 따옴표 안에 이름을 적어요(예:"엄마"). 끝인사 「메리 크리스마스」 아래에 그 이름이 나와요. 비워 두면 「메리 크리스마스」만 나와요. - 전구 개수:
for (let i = 0; i < 170; i++)의 170 - 장식 공 색:
paint줄의 세 묶음(빨강 · 금 · 은) - 눈송이 개수: 「눈」 부분의 240
- 뒤 풍경 빼기: 「트리를 짓는 코드」 안의
q.ridge·q.tower·q.apartments·q.rooftops·q.window·q.beacon·q.cart줄 가운데 빼고 싶은 줄을 지우면 그 풍경만 빠져요.
숫자를 바꾸기 어렵다면 클로드에게 코드와 함께 「전구를 300개로 바꿔 줘」처럼 말로 시켜도 돼요.
3. 알아 둘 것
- 설치할 것도, 인터넷 연결도 필요 없어요. 파일 한 장이 전부예요.
- 릴스 속 음악에 맞춰 트리가 흔들리고 물결이 퍼지는 움직임은 영상에만 넣은 효과예요. 파일을 열면 음악 없이 트리가 자라는 화면이 나와요.
- 글자 모양은 기기에 깔린 글꼴에 따라 조금 달라 보일 수 있어요.
4. 코드 전체
<!doctype html>
<html lang="ko">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>코드로 그린 크리스마스 트리</title>
<style>
html, body { margin: 0; height: 100%; background: #04060c; overflow: hidden; }
body { display: flex; align-items: center; justify-content: center; }
canvas { height: 100vh; max-width: 100vw; aspect-ratio: 9 / 16; object-fit: contain; cursor: pointer; }
</style>
</head>
<body>
<canvas id="화면" width="1080" height="1920"></canvas>
<script>
// ───────── 여기만 고치면 내 트리가 돼요 ─────────
const 받는사람 = ""; // 트리를 선물할 사람 이름(예: "엄마") · 비워 두면 「메리 크리스마스」만 나와요
// ───────── 트리를 짓는 코드 ─────────
// 아래 글자가 화면 아래 창에 그대로 쳐지고, 쳐지는 만큼 위에 그려져요.
// 트리(q.add · q.ball · q.light…)와 뒤의 서울 밤 풍경(q.ridge · q.tower · q.apartments…)이 같이 만들어져요.
const TAU = Math.PI * 2, Y0 = 0.3, Y1 = 2.62;
function build(q, win, rng) {
// --- 줄기
let [a0, a1] = win('줄기');
for (let i = 0; i < 260; i++) {
const h = i / 260, a = rng() * TAU, r = 0.085 - 0.045 * h;
q.add([r * Math.cos(a), h * (Y1 - 0.5), r * Math.sin(a)], [0.6, 0.4, 0.22], 'bark', a0 + h * (a1 - a0));
}
// --- 가지: 층층이 처진 가지, 반쯤 자라면 뒤로 산 능선도 같이
[a0, a1] = win('가지');
for (let i = 0; i < 18; i++) {
const y = Y0 + 0.16 + (Y1 - Y0 - 0.12) * i / 18, R = envelope(y);
const nb = Math.round(6 + 9 * R), t0 = a0 + (a1 - a0) * i / 18;
if (i >= 8) q.ridge((i - 8) / 10, t0);
for (let b = 0; b < nb; b++) {
const a = TAU * b / nb + i * 0.618 * TAU + 0.12 * rng();
const L = R * (0.82 + 0.24 * rng()), n = Math.round(16 + 70 * L);
const d = [Math.cos(a), 0, Math.sin(a)], side = [-d[2], 0, d[0]];
for (let k = 0; k < n; k++) {
const s = rng() ** 0.65, spread = (0.012 + 0.075 * s) * (0.3 + 0.7 * R) * rng.normal();
const yy = y + 0.1 * s - 0.34 * s * s + 0.02 * rng.normal();
const p = [d[0] * s * L + side[0] * spread, yy, d[2] * s * L + side[2] * spread];
const tone = (0.35 + 0.65 * s ** 1.3) * (0.55 + 0.6 * rng());
q.add(p, [0.1 + 0.22 * tone, 0.34 + 0.66 * tone, 0.1 + 0.24 * tone], 'needle', t0 + (a1 - a0) / 18 * rng());
if (s > 0.9) q.tips.push(p);
}
}
}
// --- 눈꽃: 가지 끝에 눈이 앉고, 언덕 위에 남산타워가 선다
[a0, a1] = win('눈꽃');
for (const p of q.tips) {
if (rng() < 0.16) q.add([p[0], p[1] + 0.03, p[2]], [0.94, 0.97, 1], 'snow', a0 + (a1 - a0) * rng());
}
q.tower(a0, a1);
// --- 장식 줄: 금빛 줄이 돌아 오르고, 아파트가 올라온다
[a0, a1] = win('장식 줄');
for (let i = 0; i < 3000; i++) {
const u = i / 3000, y = Y0 + 0.14 + (Y1 - Y0 - 0.5) * u, a = TAU * 5.5 * u;
const r = envelope(y) * 0.96 + 0.012 * rng.normal();
q.add([r * Math.cos(a), y - 0.05 * Math.sin(a * 3), r * Math.sin(a)], [1, 0.8, 0.3], 'garland', a0 + (a1 - a0) * u);
}
q.apartments(a0, a1);
// --- 장식 공: 빨강 · 금 · 은빛 공, 남산 아래 동네 지붕
[a0, a1] = win('장식 공');
const paint = [[0.9, 0.1, 0.2], [0.98, 0.74, 0.24], [0.82, 0.86, 0.94]];
for (let i = 0; i < 26; i++) {
const y = Y0 + 0.14 + (Y1 - Y0 - 0.6) * (1 - Math.sqrt(1 - (i + 0.5) / 26));
const a = i * 2.4 + rng(), r = envelope(y) * 0.95;
q.ball([r * Math.cos(a), y - 0.05, r * Math.sin(a)], 0.032 + 0.01 * rng(), paint[i % 3], a0 + (a1 - a0) * i / 26);
}
q.rooftops(a0, a1);
// --- 전구: 전구 170개가 켜질 때 창문 불빛도 켜진다
[a0, a1] = win('전구');
for (let i = 0; i < 170; i++) {
const y = Y0 + 0.06 + (Y1 - Y0 - 0.25) * (1 - Math.sqrt(1 - (i + 0.5) / 170));
const a = i * 2.39996 + 0.6 * rng(), r = envelope(y) * (0.9 + 0.12 * rng());
q.light([r * Math.cos(a), y, r * Math.sin(a)], a0 + (a1 - a0) * i / 170);
if (i % 2) q.window(a0 + (a1 - a0) * i / 170);
}
// --- 별: 꼭대기에 별, 남산타워에도 불
[a0, a1] = win('별');
q.star([0, Y1 + 0.17, 0], 0.15, a0 + 0.6 * (a1 - a0));
q.beacon(a0 + 0.6 * (a1 - a0));
// --- 선물: 선물 상자 옆에 붕어빵 포장마차
[a0, a1] = win('선물');
const red = [0.82, 0.1, 0.18], gold = [0.86, 0.68, 0.24], blue = [0.16, 0.24, 0.72], white = [0.86, 0.88, 0.94];
const boxes = [[0.8, 0.3, 0.26, 0.24, gold, red], [-0.72, -0.42, 0.23, 0.27, red, white], [0.2, -0.84, 0.21, 0.18, blue, gold], [-0.3, 0.8, 0.18, 0.15, white, red]];
boxes.forEach(([x, z, w, h, color, ribbon], i) => q.box([x, 0, z], w, h, color, ribbon, a0 + (a1 - a0) * i / boxes.length));
q.cart(a0, a1);
// --- 눈: 하늘에서 눈이 내린다
[a0, a1] = win('눈');
for (let i = 0; i < 240; i++) {
q.flake([3.2 * (rng() - 0.5), 3.5 * rng(), 3.2 * (rng() - 0.5)], 0.22 + 0.3 * rng(), a0 + (a1 - a0) * rng());
}
}
function envelope(y) {
// --- 도우미: 트리의 둥근 윤곽과 난수
const h = Math.min(1, Math.max(0, (y - Y0) / (Y1 - Y0)));
return 0.06 + 0.88 * Math.pow(1 - h, 0.74) * (0.92 + 0.08 * Math.cos(h * 26));
}
function makeRng(seed) {
let s = seed >>> 0;
const rng = () => {
s = (s + 0x6D2B79F5) | 0;
let t = Math.imul(s ^ (s >>> 15), 1 | s);
t = (t + Math.imul(t ^ (t >>> 7), 61 | t)) ^ t;
return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
};
rng.normal = () => Math.sqrt(-2 * Math.log(1 - rng())) * Math.cos(TAU * rng());
return rng;
}
function finale(q, win) {
// --- 인사: 받는 사람 이름으로 끝인사
const [a0, a1] = win('인사');
q.greet('메리 크리스마스', 받는사람 + '에게', a1);
}
// ───────── 아래는 글자로 그리는 엔진(고치지 않아도 돼요) ─────────
(function () {
'use strict';
const W = 1080, H = 1920, PY = 1365, CW = 11, CH = 19.5, COLS = Math.ceil(W / CW), ROWS = Math.round(PY / CH), N = COLS * ROWS;
const CX = 540, GY = 1212, S = 348, CAM = 7, TILT = 0.165, HORIZON = 1035;
const cv = document.getElementById('화면'), X = cv.getContext('2d');
const MONO = 'Menlo, Consolas, "DejaVu Sans Mono", "Courier New", monospace';
const SANS = 'Pretendard, "Apple SD Gothic Neo", "Malgun Gothic", "Noto Sans KR", sans-serif';
const 설정 = window.트리설정 || {};
const cl = (x, a = 0, b = 1) => Math.max(a, Math.min(b, x)), seg = (t, a, b) => cl((t - a) / (b - a)), ease = x => 1 - Math.pow(1 - x, 3);
const back = x => x <= 0 ? 0 : x >= 1 ? 1 : 1 + 2.70158 * Math.pow(x - 1, 3) + 1.70158 * Math.pow(x - 1, 2);
const hash = (a, b) => { let h = (a * 374761393 + b * 668265263) | 0; h = (h ^ (h >>> 13)) * 1274126177 | 0; return ((h ^ (h >>> 16)) >>> 0) / 4294967296; };
// ── 1) 코드 읽기: 위 함수들의 글자가 그대로 코드 창에 쳐진다
const lines = [build, envelope, makeRng, finale].map(f => f.toString()).join('\n\n').split('\n');
const names = [], labels = [], lineSec = [];
{ let k = -1; lines.forEach((s, i) => { const m = s.match(/^\s*\/\/ --- (.+)$/); if (m) { k++; labels.push(m[1].trim()); names.push(m[1].split(':')[0].trim()); } lineSec[i] = Math.max(0, k); }); }
function 기본구간() { let t = 0; const w = {}; names.forEach((n, k) => { let c = 0; lines.forEach((s, i) => { if (lineSec[i] === k) c += s.trim().length + 6; }); w[n] = [t, t + c]; t += c; }); const k = 24 / t; names.forEach(n => { w[n] = [0.4 + w[n][0] * k, 0.4 + w[n][1] * k]; }); return w; }
let 구간, lineA, lineB, 오류 = null;
// ── 2) 장면: build()가 넣어 주는 점 · 공 · 전구 · 별 · 상자 · 눈송이
const KIND = { bark: 0, needle: 1, snow: 2, garland: 3, ball: 4, gift: 5 };
let P, lights, balls, flakes, star, greet, dots = null;
function 다시짓기(새구간) {
구간 = 새구간 || 설정.구간 || 기본구간();
lineA = []; lineB = [];
names.forEach((n, k) => { const [a, b] = 구간[n] || [1e9, 1e9]; const idx = lines.map((_, i) => i).filter(i => lineSec[i] === k); const tot = idx.reduce((s, i) => s + lines[i].trim().length + 6, 0); let acc = 0; idx.forEach(i => { lineA[i] = a + (b - a) * acc / tot; acc += lines[i].trim().length + 6; lineB[i] = a + (b - a) * acc / tot; }); });
const px = [], py = [], pz = [], pr = [], pg = [], pb = [], pk = [], pt = [];
lights = []; balls = []; flakes = []; star = null; greet = null; dots = null;
뒤 = []; 창 = []; 간판 = []; 탑 = null; 수레 = null;
const r2 = makeRng(99);
const q = {
tips: [], ...뒷배경짓기,
add(p, c, kind, t) { px.push(p[0]); py.push(p[1]); pz.push(p[2]); pr.push(c[0]); pg.push(c[1]); pb.push(c[2]); pk.push(KIND[kind] || 0); pt.push(t); },
ball(c, rad, col, t) { balls.push({ c, rad, col, t }); for (let i = 0; i < 14; i++) { const u = 1 - 2 * (i + 0.5) / 14, rr = Math.sqrt(1 - u * u), a = i * 2.39996; q.add([c[0] + rad * rr * Math.cos(a), c[1] + rad * u, c[2] + rad * rr * Math.sin(a)], [cl(col[0] + 0.25 * (u + 0.3)), cl(col[1] + 0.2 * (u + 0.3)), cl(col[2] + 0.2 * (u + 0.3))], 'ball', t + 0.12 * r2()); } },
light(p, t) { lights.push({ p, t, ph: r2() * TAU, sp: 2 + 3.5 * r2() }); },
star(p, rad, t) { star = { p, rad, t }; },
box(c, w, h, col, rib, t) { const hw = w / 2, n = 9; for (let f = 0; f < 5; f++) for (let i = 0; i <= n; i++) for (let j = 0; j <= n; j++) { const u = i / n * 2 - 1, v = j / n; let p; if (f === 4) p = [c[0] + u * hw, c[1] + h, c[2] + (v * 2 - 1) * hw]; else { const s = f < 2 ? 1 : -1; p = f % 2 ? [c[0] + s * hw, c[1] + v * h, c[2] + u * hw] : [c[0] + u * hw, c[1] + v * h, c[2] + s * hw]; } const ribbon = Math.abs(u) < 0.16 || (f === 4 && Math.abs(v * 2 - 1) < 0.16); q.add(p, ribbon ? rib : col, 'gift', t + 0.5 * v + 0.05 * r2()); } },
flake(p, v, t) { flakes.push({ p, v, t, ph: r2() * TAU }); },
greet(a, b, t) { greet = { a, b, t }; },
};
const 빠르기 = 설정.트리빠르기 || 1.2; // 트리가 자라는 속도(코드 치는 속도는 그대로)
const win = n => { const w = 구간[n]; const k = n === '인사' ? 1 : 빠르기; return w ? [w[0], w[0] + (w[1] - w[0]) / k] : [1e9, 1e9]; };
try { build(q, win, makeRng(7)); finale(q, win); } catch (e) { 오류 = e; }
뒤.sort((a, b) => a.z - b.z);
P = { n: px.length, x: Float32Array.from(px), y: Float32Array.from(py), z: Float32Array.from(pz), r: Float32Array.from(pr), g: Float32Array.from(pg), b: Float32Array.from(pb), k: Uint8Array.from(pk), t: Float32Array.from(pt) };
}
// ── 2-1) 뒷배경: 서울의 밤 — 산 능선 · 남산타워 · 아파트 · 동네 지붕 · 붕어빵 포장마차(트리와 달리 돌지 않는다)
const BASE = Math.floor(HORIZON / CH) - 1, TOWER = 85, 가림 = new Uint8Array(N);
let 뒤 = [], 창 = [], 간판 = [], 탑 = null, 수레 = null, 뒷빛 = [];
const 능선높이 = c => 6 + 3.2 * Math.sin(c * 0.085 + 0.6) + 1.8 * Math.sin(c * 0.21 + 2) + Math.sin(c * 0.47);
const 남산높이 = c => 13.4 * Math.max(0, 1 - ((c - TOWER) / 25) ** 2);
function 칸(z, c, r, ch, col, fill, t) { const o = { z, c, r, ch, col, fill, t, lit: 1e9, ph: hash(c, r) * TAU }; if (c >= 0 && c < COLS && r >= 0 && r < ROWS) 뒤.push(o); return o; }
function 건물(c0, w, h, a0, a1, 번호) {
for (let k = 0; k < h; k++) for (let i = 0; i < w; i++) {
const top = k === h - 1, win = !top && i % 2 === 1, t = a0 + (a1 - a0) * (k + 0.6 * hash(c0 + i, k)) / h, v = hash(c0 + i, k + 50);
let ch = top || win ? '=' : i === 0 || i === w - 1 ? '|' : ':', col = top ? [104, 116, 150] : win ? [52, 62, 96] : [40, 48, 78];
if (top && 번호 && i >= 2 && i < 2 + 번호.length) { ch = 번호[i - 2]; col = [156, 168, 202]; }
const o = 칸(3, c0 + i, BASE - k, ch, col, [19, 24, 44], t);
if (win) { o.warm = v < 0.72 ? [255, 212, 138] : v < 0.9 ? [214, 228, 255] : [255, 170, 96]; 창.push(o); }
}
}
const 뒷배경짓기 = {
ridge(u, t) { // 산 능선: 화면 너비의 u ~ u+0.1 구간을 그린다. 오른쪽 끝은 남산
for (let c = Math.round(u * COLS); c < Math.round((u + 0.1) * COLS); c++) {
const h = Math.round(능선높이(c)), n = Math.floor(남산높이(c));
for (let k = 0; k < h; k++) 칸(0, c, BASE - k, k === h - 1 ? '^' : hash(c, k) > 0.6 ? ':' : '.', k === h - 1 ? [92, 106, 142] : [38, 48, 78], [10, 13, 27], t + 0.03 * k + 0.1 * hash(c, k + 9));
for (let k = 0; k < n; k++) 칸(1, c, BASE - k, k === n - 1 ? '^' : hash(c, k + 3) > 0.55 ? '*' : '"', k === n - 1 ? [84, 104, 122] : [28, 52, 50], [7, 11, 19], t + 0.03 * k + 0.1 * hash(c, k + 5));
}
},
tower(a0, a1) { // 남산타워: 아래에서 위로 선다
const top = BASE - Math.floor(남산높이(TOWER)), rows = ['+', '|', '|', '|', '|', '|', '|', '[#]', '=====', '(###)', '#', '#', '#', '#', '#', '#'];
rows.forEach((s, i) => { const r = top - rows.length + 1 + i, t = a0 + (a1 - a0) * (rows.length - 1 - i) / rows.length; [...s].forEach((ch, k) => { const o = 칸(2, TOWER - (s.length >> 1) + k, r, ch, i < 7 ? [116, 126, 156] : [150, 160, 192], i >= 7 ? [24, 29, 50] : null, t); o.part = i === 0 ? 'tip' : i >= 7 && i <= 9 ? 'pod' : ''; }); });
탑 = { x: (TOWER + 0.5) * CW, y: (top - 7.5) * CH, tipY: (top - rows.length + 1.5) * CH, lit: 1e9 };
},
beacon(t) { if (탑) 탑.lit = t; }, // 남산타워에 불
apartments(a0, a1) { [[1, 7, 13, '101'], [9, 7, 16, '102'], [17, 7, 11, '103']].forEach(([c, w, h, 번호], i) => 건물(c, w, h, a0 + (a1 - a0) * 0.18 * i, a0 + (a1 - a0) * (0.64 + 0.18 * i), 번호)); },
rooftops(a0, a1) { // 남산 아래 동네: 낮은 건물과 간판
[[66, 5, 4], [71, 4, 6], [75, 5, 3], [80, 6, 5], [86, 4, 3], [90, 5, 6], [95, 4, 4]].forEach(([c, w, h], i) => 건물(c, w, h, a0 + (a1 - a0) * 0.1 * i, a0 + (a1 - a0) * (0.4 + 0.1 * i)));
간판.push({ x: 83 * CW, y: (BASE - 5 + 0.5) * CH, 글: '치킨', col: [255, 150, 70], t: a0 + (a1 - a0) * 0.7, lit: 1e9 }, { x: 92.5 * CW, y: (BASE - 6 + 0.5) * CH, 글: '노래방', col: [255, 110, 170], t: a1, lit: 1e9 });
},
window(t) { // 창문 하나에 불을 켠다(순서는 섞여 있다)
if (!창.순서) { 창.순서 = 창.map((o, i) => [hash(i, 77), o]).sort((a, b) => a[0] - b[0]).map(v => v[1]); 창.n = 0; }
const k = 창.n++, o = 창.순서[k]; if (o) o.lit = t; if (k === 2 && 간판[0]) 간판[0].lit = t; if (k === 8 && 간판[1]) 간판[1].lit = t;
},
cart(a0, a1) { // 붕어빵 포장마차: 바퀴부터 천막까지
const c0 = 2, r0 = BASE + 1, 그림 = [' /==========\\ ', ' /============\\ ', ' [ ] ', ' [ ] ', ' | o o o | ', ' | <>< <>< <><| ', ' +============+ ', ' |############| ', ' O O '];
그림.forEach((s, i) => [...s].forEach((ch, k) => {
const t = a0 + (a1 - a0) * (0.8 * (8 - i) / 8 + 0.12 * hash(k, i)), 안 = k >= 1 && k <= 14;
if (i === 8) { if (ch !== ' ') 칸(5, c0 + k, r0 + i, ch, [150, 156, 176], null, t); return; }
if (i < 2) { if (ch !== ' ') 칸(5, c0 + k, r0 + i, ch, [255, 176, 96], ch === '=' ? (k % 2 ? [206, 92, 30] : [166, 64, 22]) : null, t); return; }
if (!안) return;
const o = 칸(5, c0 + k, r0 + i, ch, i < 4 ? [206, 120, 92] : i === 4 ? (ch === 'o' ? [255, 232, 160] : [150, 110, 80]) : i === 5 ? (ch === '|' ? [150, 110, 80] : [244, 182, 84]) : i === 6 ? [222, 178, 116] : [92, 132, 152], i < 4 ? [112, 22, 30] : i < 6 ? [44, 26, 14] : i === 6 ? [120, 82, 44] : [30, 50, 66], t);
if (i === 4 && ch === 'o') o.bulb = 1;
}));
수레 = { x: (c0 + 8) * CW, signY: (r0 + 3) * CH, midY: (r0 + 4.5) * CH, top: r0, t: a1 };
},
};
function 뒷배경(t) {
let 글자 = 0; 뒷빛 = [];
X.textAlign = 'center'; X.textBaseline = 'middle'; X.font = `700 19px ${MONO}`;
const 탑불 = 탑 ? seg(t, 탑.lit, 탑.lit + 0.5) : 0;
for (const o of 뒤) {
const age = t - o.t; if (age < 0) continue;
const j = o.r * COLS + o.c; if (cnt[j] > 0 && kd[j] !== 6) continue;
const x = o.c * CW, y = o.r * CH; let col = o.col, fill = o.fill;
if (탑불 > 0 && o.part === 'pod') { col = [200, 236, 255]; fill = [24 + 30 * 탑불 | 0, 29 + 70 * 탑불 | 0, 50 + 90 * 탑불 | 0]; }
if (fill) { X.fillStyle = `rgb(${fill[0]},${fill[1]},${fill[2]})`; X.fillRect(x, y, CW + 0.5, CH + 0.5); }
if (cnt[j] > 0) continue;
if (o.warm && t >= o.lit) { const on = seg(t, o.lit, o.lit + 0.25), tw = 0.86 + 0.14 * Math.sin(t * 1.7 + o.ph); X.fillStyle = `rgba(${o.warm[0]},${o.warm[1]},${o.warm[2]},${(0.88 * on * tw).toFixed(3)})`; X.fillRect(x + 1.5, y + 3.5, CW - 3, CH - 7); if (hash(o.c, o.r + 7) > 0.45) 뒷빛.push(['l', [255, 226, 160], x + CW / 2, y + CH / 2, 17, 0.3 * on * tw]); 글자++; continue; }
if (o.ch === ' ') continue;
if (o.part === 'tip' && 탑불 > 0) { const 깜 = Math.sin(t * 4.4) > 0 ? 1 : 0.25; col = [255, 80 * 깜 + 20, 80 * 깜 + 20].map(v => v | 0); 뒷빛.push(['r', [255, 60, 60], x + CW / 2, y + CH / 2, 26, 0.7 * 깜 * 탑불]); }
if (o.bulb) 뒷빛.push(['l', [255, 226, 160], x + CW / 2, y + CH / 2, 24, 0.55 * seg(age, 0, 0.3)]);
const w = age < 0.3 ? (1 - age / 0.3) * 110 : 0;
X.fillStyle = `rgb(${Math.min(255, col[0] + w) | 0},${Math.min(255, col[1] + w) | 0},${Math.min(255, col[2] + w) | 0})`; X.fillText(o.ch, x + CW / 2, y + CH / 2); 글자++;
}
if (탑 && 탑불 > 0) 뒷빛.push(['p', [120, 200, 255], 탑.x, 탑.y, 64, 0.42 * 탑불]);
for (const g of 간판) { if (t < g.t) continue; const on = seg(t, g.lit, g.lit + 0.2), 깜 = on > 0 && on < 1 ? 0.6 + 0.4 * Math.sin(t * 40) : 1; X.font = `800 21px ${SANS}`; X.fillStyle = on > 0 ? `rgba(${g.col[0]},${g.col[1]},${g.col[2]},${(0.95 * 깜).toFixed(2)})` : 'rgb(58,66,98)'; X.fillText(g.글, g.x, g.y); if (on > 0) 뒷빛.push(['g' + g.글, g.col, g.x, g.y, 46, 0.3 * on]); }
if (수레 && t >= 수레.t - 0.15) {
const pop = back(seg(t, 수레.t - 0.15, 수레.t + 0.25)), age = t - 수레.t;
X.save(); X.translate(수레.x, 수레.signY); X.scale(pop, pop); X.font = `900 31px ${SANS}`; X.fillStyle = 'rgb(255,216,112)'; X.fillText('붕 어 빵', 0, 1); X.restore();
뒷빛.push(['l', [255, 200, 120], 수레.x, 수레.midY, 96, 0.38 * seg(age, -0.15, 0.4)]);
X.font = `700 19px ${MONO}`;
for (let k = 0; k < 5; k++) { const ph = (Math.max(0, age) * 0.42 + k / 5) % 1, c = Math.round((수레.x + (k - 2) * 20 + 9 * Math.sin(t * 1.1 + k * 2.1)) / CW), r = 수레.top - 1 - Math.floor(ph * 4); if (r < 0 || cnt[r * COLS + c] > 0) continue; X.fillStyle = `rgba(236,240,248,${((1 - ph) * 0.6 * seg(age, 0, 0.6)).toFixed(3)})`; X.fillText(ph < 0.5 ? '~' : '.', (c + 0.5) * CW, (r + 0.5) * CH); 글자++; }
}
X.font = `700 19px ${MONO}`;
return 글자;
}
// ── 3) 빛 번짐 그림(미리 만들어 둠)
const 번짐 = {};
function glow(key, r, g, b) { if (!번짐[key]) { const c = document.createElement('canvas'); c.width = c.height = 128; const q = c.getContext('2d'), gr = q.createRadialGradient(64, 64, 0, 64, 64, 64); gr.addColorStop(0, `rgba(${r},${g},${b},1)`); gr.addColorStop(0.18, `rgba(${r},${g},${b},0.55)`); gr.addColorStop(0.5, `rgba(${r},${g},${b},0.14)`); gr.addColorStop(1, `rgba(${r},${g},${b},0)`); q.fillStyle = gr; q.fillRect(0, 0, 128, 128); 번짐[key] = c; } return 번짐[key]; }
function shine(key, rgb, x, y, rad, a) { if (a <= 0.01) return; X.globalAlpha = cl(a); X.drawImage(glow(key, rgb[0], rgb[1], rgb[2]), x - rad, y - rad, rad * 2, rad * 2); X.globalAlpha = 1; }
// ── 4) 한 장 그리기
const cnt = new Float32Array(N), dep = new Float32Array(N), dz = new Float32Array(N), cr = new Float32Array(N), cg = new Float32Array(N), cb = new Float32Array(N), fl = new Float32Array(N), kd = new Uint8Array(N);
const sky = (() => { const r = makeRng(5), a = []; for (let i = 0; i < 170; i++) a.push({ c: Math.floor(r() * COLS), r: Math.floor(r() * r() * ROWS * 1.05), g: r() < 0.14 ? '*' : r() < 0.3 ? '+' : '.', a: 0.25 + 0.7 * r(), ph: r() * TAU, sp: 0.5 + 2 * r() }); return a; })();
let 상태 = { 글자: 0, 전구: 0, 회전: 0 };
function 그리기(t, 덧) {
덧 = 덧 || {};
X.setTransform(1, 0, 0, 1, 0, 0); X.globalAlpha = 1; X.globalCompositeOperation = 'source-over';
const bg = X.createLinearGradient(0, 0, 0, PY); bg.addColorStop(0, '#090d1c'); bg.addColorStop(1, '#121831');
X.fillStyle = bg; X.fillRect(0, 0, W, H);
if (오류) { X.fillStyle = '#fff'; X.font = `700 40px ${SANS}`; X.textAlign = 'center'; X.fillText('코드에 틀린 곳이 있어요', CX, 860); X.font = `500 26px ${MONO}`; X.fillText(String(오류.message).slice(0, 44), CX, 930); return; }
const tg = greet ? greet.t : 1e9, 끝 = seg(t, tg - 0.25, tg + 0.35);
const 자람 = seg(t, (구간['가지'] || [0, 1])[0], (구간['가지'] || [0, 1])[1]), 불 = seg(t, (구간['전구'] || [1e9, 1e9])[0], (구간['전구'] || [1e9, 1e9])[1]);
shine('warm', [150, 110, 70], CX, 760, 620, 0.2 + 0.25 * 불);
const th = (설정.처음각 != null ? 설정.처음각 : 3.5) + 0.31416 * t, co = Math.cos(th), si = Math.sin(th), ct = Math.cos(TILT), st = Math.sin(TILT);
cnt.fill(0); dep.fill(-1e9); fl.fill(0);
const M = 설정.움직임 ? 설정.움직임(t) : null, SW = M ? M.sway : 0, SX = M ? 1 + M.bx : 1, SYc = M ? 1 + M.by : 1, 펄 = M ? M.pulse : 0;
const 물결 = (x, y) => { if (!M) return 0; let v = 0; for (const w of M.waves) { const d = Math.hypot(x - CX, (y - GY - 18) * 3.2) - w.R; v += 1.3 * w.s * Math.exp(-d * d / 2200); } return Math.min(1, v); };
const proj = (x, y, z, f = 1) => { const x1 = (x * co + z * si) * (f ? SX : 1) + (f ? SW * y : 0), z1 = -x * si + z * co, y2 = (y * ct - z1 * st) * (f ? SYc : 1), z2 = y * st + z1 * ct, k = CAM / (CAM - z2); return [CX + x1 * S * k, GY - y2 * S * k, z2, z1, k]; };
const { n, x: ax, y: ay, z: az, r: ar, g: ag, b: ab, k: ak, t: at } = P;
for (let i = 0; i < n; i++) {
const age = t - at[i]; if (age < 0) continue;
const x = ax[i], y = ay[i], z = az[i], x1 = (x * co + z * si) * SX + SW * y, z1 = -x * si + z * co, y2 = (y * ct - z1 * st) * SYc, z2 = y * st + z1 * ct, k = CAM / (CAM - z2);
const col = Math.floor((CX + x1 * S * k) / CW), row = Math.floor((GY - y2 * S * k) / CH);
if (col < 0 || col >= COLS || row < 0 || row >= ROWS) continue;
const j = row * COLS + col, kind = ak[i];
cnt[j] += z1 > -0.08 ? 1 : 0.42;
const d = z2 + (kind >= 3 ? 0.12 : 0);
if (d > dep[j]) { dep[j] = d; dz[j] = z1; cr[j] = ar[i]; cg[j] = ag[i]; cb[j] = ab[i]; kd[j] = kind; fl[j] = age < 0.3 ? 1 - age / 0.3 : 0; }
}
// 내리는 눈
for (const f of flakes) { const age = t - f.t; if (age < 0) continue; const y = 3.5 - ((3.5 - f.p[1] + f.v * age) % 3.5), s = proj(f.p[0] + 0.06 * Math.sin(age * 1.3 + f.ph), y, f.p[2], 0); const col = Math.floor(s[0] / CW), row = Math.floor(s[1] / CH); if (col < 0 || col >= COLS || row < 0 || row >= ROWS) continue; const j = row * COLS + col; if (s[2] > dep[j]) { dep[j] = s[2]; dz[j] = 1; cnt[j] = Math.max(cnt[j], 1); cr[j] = 0.95; cg[j] = 0.97; cb[j] = 1; kd[j] = 6; fl[j] = 0; } }
// 전구는 글자 칸에도 찍힌다
let 켜진 = 0; const 빛 = [];
for (const L of lights) { const age = t - L.t; if (age < 0) continue; 켜진++; const s = proj(L.p[0], L.p[1], L.p[2]), tw = Math.min(1.3, (0.55 + 0.45 * Math.sin(t * L.sp + L.ph)) * (1 + 0.8 * 펄)), vis = s[3] > -0.12 ? 1 : 0.28; 빛.push([s[0], s[1], tw * vis * seg(age, 0, 0.2), tw]); const col = Math.floor(s[0] / CW), row = Math.floor(s[1] / CH); if (vis === 1 && col >= 0 && col < COLS && row >= 0 && row < ROWS) { const j = row * COLS + col; if (s[2] + 0.2 > dep[j]) { dep[j] = s[2] + 0.2; dz[j] = 1; cnt[j] = Math.max(cnt[j], 1); cr[j] = 1; cg[j] = 0.9; cb[j] = 0.6; kd[j] = tw > 0.8 ? 8 : 7; fl[j] = 0; } } }
// 밤하늘 · 땅 · 트리 글자
X.textAlign = 'center'; X.textBaseline = 'middle'; X.font = `700 19px ${MONO}`;
let 글자 = 0;
가림.fill(0); for (const o of 뒤) if (t >= o.t) 가림[o.r * COLS + o.c] = 1;
for (const s of sky) { if (s.r >= ROWS || cnt[s.r * COLS + s.c] > 0 || 가림[s.r * COLS + s.c]) continue; X.fillStyle = `rgba(235,240,255,${(s.a * (0.6 + 0.4 * Math.sin(t * s.sp + s.ph)) * (s.r * CH > HORIZON ? 0.6 : 1)).toFixed(3)})`; X.fillText(s.g, (s.c + 0.5) * CW, (s.r + 0.5) * CH); 글자++; }
if (M) for (const w of M.waves) { if (w.s < 0.05) continue; for (const [dr, aa] of [[0, 1], [-24, 0.55]]) { const RR = w.R + dr; if (RR < 10) continue; const n = Math.ceil(TAU * RR / CW); for (let k = 0; k <= n / 2; k++) { const an = Math.PI * k / (n / 2), col = Math.floor((CX + Math.cos(an) * RR) / CW), row = Math.floor((GY + 18 - Math.sin(an) * RR) / CH); if (col < 0 || col >= COLS || row < 0 || row * CH >= HORIZON) continue; const j = row * COLS + col; if (cnt[j] > 0 || 가림[j]) continue; X.fillStyle = `rgba(200,225,255,${Math.min(1, 1.1 * w.s * aa).toFixed(3)})`; X.fillText(dr ? '.' : hash(col, row) > 0.5 ? '*' : 'o', (col + 0.5) * CW, (row + 0.5) * CH); 글자++; } } }
const r0 = Math.floor(HORIZON / CH), 못 = 덧.빈칸 || [];
for (let row = r0; row < ROWS; row++) { const y = (row + 0.5) * CH, far = (row - r0) / (ROWS - r0); for (let col = 0; col < COLS; col++) { const j = row * COLS + col; if (cnt[j] > 0 || 가림[j]) continue; const x = (col + 0.5) * CW; if (못.some(b => x > b[0] && x < b[2] && y > b[1] && y < b[3])) continue; const h = hash(col, row), ex = (x - CX) / (150 + 250 * 자람), ey = (y - GY - 18) / (22 + 46 * 자람), dd = ex * ex + ey * ey; if (dd < 1) { X.fillStyle = `rgba(${200 + 40 * 불 | 0},${208 + 20 * 불 | 0},${235 - 40 * 불 | 0},${(0.35 + 0.6 * (1 - dd)).toFixed(3)})`; X.fillText('+', x, y); 글자++; } else { const wv = 물결(x, y); if (h > 0.3 || wv > 0.28) { X.fillStyle = `rgba(${112 + 143 * wv | 0},${126 + 110 * wv | 0},${170 + 80 * wv | 0},${(0.1 + 0.3 * far + 0.6 * wv).toFixed(3)})`; X.fillText(wv > 0.5 ? '~' : h > 0.52 ? '=' : '-', x, y); 글자++; } } } }
if (M) for (const w of M.waves) { if (w.s < 0.05) continue; const n = Math.ceil(TAU * w.R / CW * 0.7); for (let k = 0; k < n; k++) { const an = TAU * k / n, col = Math.floor((CX + Math.cos(an) * w.R) / CW), row = Math.floor((GY + 18 + Math.sin(an) * w.R / 3.4) / CH); if (col < 0 || col >= COLS || row < r0 || row >= ROWS) continue; const j = row * COLS + col; if (cnt[j] > 0 || 가림[j]) continue; X.fillStyle = `rgba(170,230,255,${Math.min(1, 1.15 * w.s).toFixed(3)})`; X.fillText('~', (col + 0.5) * CW, (row + 0.5) * CH); 글자++; } }
글자 += 뒷배경(t);
for (let j = 0; j < N; j++) {
const c = cnt[j]; if (c <= 0) continue; 글자++;
const col = j % COLS, row = (j - col) / COLS, x = (col + 0.5) * CW, y = (row + 0.5) * CH, kind = kd[j], h = hash(col * 7 + 3, row * 13 + 1);
const sh = cl(0.62 + 0.55 * dz[j]) * (0.8 + 0.2 * h) * (1 + 0.32 * 펄) * (kind === 1 ? cl(0.5 + 0.13 * c, 0, 1.15) : 1), w = fl[j] * 0.7;
let ch, r = cr[j] * sh, g = cg[j] * sh, b = cb[j] * sh;
if (kind === 1) ch = c < 0.9 ? (h > 0.5 ? '-' : '=') : c < 1.5 ? (h > 0.5 ? '*' : '+') : c < 2.6 ? (h > 0.55 ? '*' : '#') : c < 4.5 ? (h > 0.4 ? '#' : '%') : '%';
else if (kind === 0) ch = h > 0.5 ? '#' : '%';
else if (kind === 2) ch = '*';
else if (kind === 3) { ch = dz[j] > 0 ? (h > 0.9 ? '*' : '~') : '='; if (h > 0.9) { r = 1; g = 0.95; b = 0.6; } }
else if (kind === 4) { ch = '@'; if (cg[j] < 0.5) { X.fillStyle = `rgba(${cr[j] * 150 | 0},${cg[j] * 110 | 0},${cb[j] * 120 | 0},0.6)`; X.fillRect(col * CW - 2, row * CH - 2, CW + 4, CH + 4); } r = cl(r + 0.25); g = cl(g + 0.2); b = cl(b + 0.2); }
else if (kind === 5) { ch = '#'; X.fillStyle = `rgba(${cr[j] * 120 | 0},${cg[j] * 120 | 0},${cb[j] * 120 | 0},0.6)`; X.fillRect(col * CW, row * CH, CW + 0.5, CH + 0.5); }
else if (kind === 6) ch = h > 0.5 ? '*' : '.';
else ch = kind === 8 ? '@' : h > 0.6 ? '0' : 'o';
X.fillStyle = `rgb(${cl(r + w) * 255 | 0},${cl(g + w) * 255 | 0},${cl(b + w) * 255 | 0})`;
X.fillText(ch, x, y);
}
// 빛 번짐: 전구 · 장식 공 · 별
X.globalCompositeOperation = 'lighter';
for (const B of balls) { const age = t - B.t; if (age < 0) continue; const s = proj(B.c[0], B.c[1], B.c[2]); if (s[3] < -0.15) continue; shine('b' + B.col.join(), B.col.map(v => v * 255 | 0), s[0], s[1], 54 * s[4], 0.5 * seg(age, 0, 0.25)); shine('w', [255, 250, 235], s[0] - 4, s[1] - 5, 15, 0.7 * seg(age, 0, 0.25)); }
for (const b of 빛) { shine('l', [255, 226, 160], b[0], b[1], 30, 0.5 * b[2]); if (b[3] > 0.85) shine('w', [255, 250, 235], b[0], b[1], 12, b[2]); }
for (const g of 뒷빛) shine(g[0], g[1], g[2], g[3], g[4], g[5]);
X.globalCompositeOperation = 'source-over';
if (star && t >= star.t) {
const age = t - star.t, pop = back(seg(age, 0, 0.45)), s = proj(star.p[0], star.p[1], star.p[2]), R = star.rad * S * s[4] * pop * (1 + 0.16 * 펄), wid = 0.35 + 0.65 * Math.abs(Math.cos(th * 1.0 + 0.6));
X.globalCompositeOperation = 'lighter'; shine('s', [255, 205, 90], s[0], s[1], R * 3.4, 0.55 + 0.1 * Math.sin(t * 3) + 0.35 * 펄); X.globalCompositeOperation = 'source-over';
X.strokeStyle = `rgba(255,214,120,${0.55 * pop})`; X.lineWidth = 2; for (let k = 0; k < 8; k++) { const a = k * TAU / 8 + 0.2 * Math.sin(t * 2 + k), L = R * (k % 2 ? 1.5 : 2.1) * (0.9 + 0.1 * Math.sin(t * 5 + k * 2)); X.beginPath(); X.moveTo(s[0] + Math.cos(a) * R * 1.1, s[1] + Math.sin(a) * R * 1.1); X.lineTo(s[0] + Math.cos(a) * L, s[1] + Math.sin(a) * L); X.stroke(); }
const path = new Path2D(); for (let k = 0; k < 10; k++) { const a = -Math.PI / 2 + k * Math.PI / 5, rr = k % 2 ? R * 0.42 : R; path[k ? 'lineTo' : 'moveTo'](s[0] + Math.cos(a) * rr * wid, s[1] + Math.sin(a) * rr); } path.closePath();
const T = 5; for (let yy = s[1] - R; yy < s[1] + R; yy += T) for (let xx = s[0] - R; xx < s[0] + R; xx += T) { if (!X.isPointInPath(path, xx + T / 2, yy + T / 2)) continue; const a = Math.atan2(yy + T / 2 - s[1], xx + T / 2 - s[0]), facet = Math.floor((a + Math.PI) / (Math.PI / 5) + 0.5) % 2, lum = (facet ? 1 : 0.74) * (0.85 + 0.15 * Math.sin(t * 4 + xx * 0.2)); X.fillStyle = `rgb(${255 * lum | 0},${205 * lum | 0},${70 * lum | 0})`; X.fillRect(xx + 0.6, yy + 0.6, T - 1.2, T - 1.2); }
}
상태 = { 글자, 전구: 켜진, 회전: ((th * 180 / Math.PI) % 360 + 360) % 360 };
// 화면 구석 글자
const hud = (1 - 끝) * (덧.구석글자 === false ? 0 : 1);
if (hud > 0) {
X.globalAlpha = hud; X.textAlign = 'left'; X.font = `500 22px ${MONO}`; X.fillStyle = 'rgba(196,205,226,0.78)';
X.fillText((설정.이름 || '@dannyoff.ai') + ' · 2026', 104, 1276);
X.fillText('회전 ' + 상태.회전.toFixed(2).padStart(6, '0') + '°', 104, 1306); X.fillText('전구 ' + String(켜진).padStart(3, ' '), 470, 1306);
X.fillText('글자 ' + 글자.toLocaleString('en-US'), 104, 1336);
let 지금 = -1; lines.forEach((_, i) => { if (t >= lineA[i]) 지금 = i; });
if (지금 >= 0 && t < lineB[lines.length - 1] + 0.6) { X.font = `700 32px ${SANS}`; const 글 = labels[lineSec[지금]], 폭 = X.measureText(글).width; X.fillStyle = 'rgba(7,10,20,0.78)'; X.fillRect(88, 1208, 폭 + 32, 48); X.fillStyle = 'rgba(255,255,255,0.95)'; X.fillText(글, 104, 1233); }
X.textAlign = 'right'; X.font = `500 21px ${MONO}`; X.fillStyle = '#ff4d7d'; X.fillText('t ' + Math.max(0, t).toFixed(2).padStart(5, '0') + 's', 978, 240); X.textAlign = 'left'; X.globalAlpha = 1;
}
코드창(t, 끝);
인사(t);
}
// ── 5) 코드 창
const 색 = { 글: '#d6deeb', 주석: '#7f8aa3', 낱말: '#c792ea', 따옴: '#c3e88d', 숫자: '#f78c6c', 수학: '#ffcb6b', 함수: '#82aaff', 기호: '#a6b0c8' };
const 낱말들 = new Set(['const', 'let', 'for', 'of', 'if', 'function', 'return', 'new']);
function 색칠(s) { if (/^\s*\/\//.test(s)) return [[s, 색.주석]]; const out = [], re = /'[^']*'?|\d+\.?\d*|0x[0-9A-Fa-f]+|[A-Za-z_$가-힣][\w$가-힣]*|\s+|./g; let m; while ((m = re.exec(s))) { const w = m[0], nx = s[re.lastIndex]; out.push([w, w[0] === "'" ? 색.따옴 : /^\d/.test(w) ? 색.숫자 : 낱말들.has(w) ? 색.낱말 : w === 'Math' || w === 'TAU' || w === 'Y0' || w === 'Y1' ? 색.수학 : /^[A-Za-z_$가-힣]/.test(w) ? (nx === '(' ? 색.함수 : 색.글) : 색.기호]); } return out; }
function 코드창(t, 끝) {
X.fillStyle = '#04070d'; X.fillRect(0, PY, W, H - PY); X.fillStyle = 'rgba(255,255,255,0.07)'; X.fillRect(0, PY, W, 1.5);
if (끝 >= 1) return;
X.globalAlpha = 1 - 끝; X.textBaseline = 'middle'; X.textAlign = 'left';
const 마지막 = lines.length - 1; let 지금 = 0, 앞 = 0; lines.forEach((_, i) => { if (t >= lineA[i]) 지금 = i; });
for (let i = 0; i <= 지금; i++) if (lines[i].trim()) 앞 = i;
X.font = `500 22px ${MONO}`; X.fillStyle = '#8b95ad'; X.fillText('js', 104, PY + 28); X.fillText('트리.js', 158, PY + 28);
X.textAlign = 'right'; X.fillText((t > lineB[마지막] ? '실행 중' : '치는 중') + ' · 60 fps', 978, PY + 28); X.textAlign = 'left';
const 줄높이 = 36, 올림 = ease(seg(t, lineA[지금], lineA[지금] + 0.1)), base = PY + 64 + 줄높이 * 2 + (1 - 올림) * 줄높이;
X.save(); X.beginPath(); X.rect(0, PY + 46, W, H); X.clip();
X.fillStyle = 'rgba(255,45,100,0.13)'; X.fillRect(96, PY + 64 + 줄높이 * 2 - 줄높이 / 2, W, 줄높이); X.fillStyle = '#ff3d6e'; X.fillRect(96, PY + 64 + 줄높이 * 2 - 줄높이 / 2, 4, 줄높이);
for (let i = Math.max(0, 지금 - 4); i <= Math.min(마지막 + 14, 지금 + 14); i++) {
const y = base + (i - 지금) * 줄높이; if (y < PY + 40 || y > H + 20) continue;
X.font = `500 21px ${MONO}`; X.textAlign = 'right'; X.fillStyle = i === 지금 ? '#e6ebf5' : '#465069'; X.fillText(String(i + 1), 150, y); X.textAlign = 'left';
if (i > 지금 || i > 마지막) continue;
const s = lines[i], 들 = s.length - s.trimStart().length, 본 = s.slice(들), 보일 = i < 지금 ? 본.length : Math.floor(seg(t, lineA[i], lineB[i]) * 본.length + 1e-6);
X.font = `500 24px ${MONO}`; let x = 178 + 들 * 14.45, 남 = 보일;
for (const [w, c] of 색칠(본)) { if (남 <= 0) break; const 글 = w.slice(0, 남); 남 -= 글.length; X.fillStyle = c; X.fillText(글, x, y); x += X.measureText(글).width; }
if (i === 지금 && t <= lineB[마지막] + 0.4) { X.fillStyle = '#ff3d6e'; X.fillRect(x + 3, y - 14, 13, 28); }
}
X.restore(); X.globalAlpha = 1;
}
// ── 6) 끝인사: 눈가루가 모여 글자가 된다
function 점만들기(text, font, cy, col, seed) { const c = document.createElement('canvas'); c.width = W; c.height = 180; const q = c.getContext('2d', { willReadFrequently: true }); q.font = font; q.textAlign = 'center'; q.textBaseline = 'middle'; q.fillStyle = '#fff'; q.fillText(text, CX, 90); const d = q.getImageData(0, 0, W, 180).data, r = makeRng(seed), out = []; for (let y = 2; y < 180; y += 5) for (let x = 2; x < W; x += 5) if (d[(y * W + x) * 4 + 3] > 110) out.push({ x, y: cy - 90 + y, sx: x + 260 * (r() - 0.5), sy: PY - 30 + 110 * r(), d: 0.4 * r(), col, tw: r() * TAU }); return out; }
function 인사(t) {
if (!greet || t < greet.t - 0.2) return;
if (!dots) dots = 점만들기(greet.a, `900 96px ${SANS}`, String(받는사람).trim() ? 1452 : 1490, [240, 243, 250], 11).concat(String(받는사람).trim() ? 점만들기(greet.b, `900 66px ${SANS}`, 1546, [246, 196, 76], 12) : []);
const u = t - greet.t, 사라짐 = 설정.인사끝 != null ? seg(t, 설정.인사끝, 설정.인사끝 + 0.45) : 0;
if (사라짐 >= 1) return;
for (const p of dots) { const k = ease(seg(u, p.d, p.d + 0.7)); if (k <= 0) continue; const x = p.sx + (p.x - p.sx) * k + (1 - k) * 14 * Math.sin(u * 9 + p.tw), y = p.sy + (p.y - p.sy) * k, a = Math.min(1, k * 2.5) * (0.84 + 0.16 * Math.sin(t * 3 + p.tw)) * (1 - 사라짐); X.fillStyle = `rgba(${p.col[0]},${p.col[1]},${p.col[2]},${a.toFixed(3)})`; X.fillRect(x - 2, y - 2 - 사라짐 * 40, 4, 4); }
if (설정.안내 !== false && u > 4) { X.globalAlpha = 0.45 * seg(u, 4, 4.8); X.fillStyle = '#fff'; X.textAlign = 'center'; X.font = `600 26px ${SANS}`; X.fillText('화면을 누르면 처음부터 다시 그려요', CX, 1840); X.globalAlpha = 1; }
}
다시짓기();
window.트리엔진 = { 그리기, 다시짓기, 구간: () => 구간, 이름들: names, 줄수: lines.length, 상태: () => 상태, 끝인사: () => greet && greet.t };
if (!설정.외부조종) {
const 멈춤 = new URLSearchParams(location.search).get('t');
if (멈춤 != null) 그리기(parseFloat(멈춤) || 0);
else { let 처음 = performance.now(); cv.addEventListener('click', () => { 처음 = performance.now(); }); (function 돌기(지금) { 그리기((지금 - 처음) / 1000); requestAnimationFrame(돌기); })(처음); }
}
})();
</script>
</body>
</html>


