LLM Coding Evaluation: A Christmas Greeting Page Benchmark with a Reproducible Scoring Framework
This article uses a Christmas greeting page as a controlled benchmark for evaluating LLM coding ability. It explains how to turn vague requirements into an acceptance-ready spec, how to control variables across models, and how to score outputs across five weighted dimensions: functional correctness, visual fidelity, performance, code quality, and compatibility. It then walks through a reference implementation covering Canvas-based snow particles, a pure-CSS Christmas tree, auto-positioned blinking lights, responsive layout, and accessibility, alongside two harder scenarios (a Canvas physics engine and an SVG rose chart). Finally, it shows how to replace subjective eyeballing with automated acceptance checks and provides the complete single-file HTML code as a baseline you can run directly.
Around every holiday season, developer communities see a fresh wave of “let AI build a holiday page” experiments. The reason is easy to understand: these tasks have an intuitive UI, short code, and instant visual feedback, which makes them convenient for getting a feel for a model’s coding ability. But there is a whole acceptance framework separating “it looks about right” from “it’s usable in a real project.”
This article does not rank specific models. Instead, it answers two questions that are more worth internalizing:
- How to design a reproducible evaluation process that turns a subjective “feels good” into comparable metrics;
- In front-end tasks constrained by “zero dependencies, single file, performance limits,” which implementation details best reveal code quality.
At the end, you’ll find the complete, runnable Christmas greeting page code and an automated acceptance checklist.
1. Why Use a “Christmas Greeting Page” as the Test Bench
On the surface, a holiday greeting page is just “background + title + tree + snowflakes.” But once you write it up as a rigorous spec, it exercises a model across four dimensions at once:
- Instruction following: whether it implements every explicit constraint on color, count, size, and animation method.
- Platform knowledge: whether it picks the right CSS and Canvas APIs and avoids common performance traps like forced reflow and layout shift.
- Completeness: whether it covers edge cases such as responsive behavior, page visibility, and the system “reduce motion” preference.
- Maintainability: whether the structure is clear, the parameters are configurable, and there’s no redundancy or unnecessary external dependencies slipped in.
So the key to judging a model isn’t whether it “can generate” something, but whether it can generate something that “runs on the first try and meets the spec.”
2. Evaluation Method: Control the Variables, Then Score Consistently
2.1 Controlling the Variables
- Same task: every candidate model receives the exact same prompt, spanning three scenario types — front-end generation, physics engines, and scientific visualization.
- Same interaction: single-shot generation with no follow-ups or additions, reproducing the real situation of a developer stating a requirement in one line.
- Same environment: all models are accessed through the same coding tool, then run and verified under the same browser and device conditions.
- Same sample data: visualization tasks use an identical dataset so differences in data difficulty don’t distort the conclusions.
2.2 Five-Dimension Scoring Table
| Dimension | Weight | Scoring Points |
|---|---|---|
| Functional correctness | 30% | Runs directly; every requirement met item by item; no errors or missing features |
| Visual fidelity | 20% | Colors, sizes, and layering match the spec; details are polished |
| Performance | 20% | Animations use only transform/opacity; no forced synchronous layout; target frame rate held steadily |
| Code quality | 15% | Structure, naming, comments, parameter configuration; no redundancy or dead code |
| Compatibility & robustness | 15% | Responsive behavior; pauses when the page is hidden; respects the system “reduce motion” setting |
One caveat worth stressing: model capabilities change continuously across versions, so any single evaluation result has a shelf life. A more durable approach is to standardize the evaluation process itself and use it as a tool for ongoing model selection and regression testing.
3. Task 1: Breaking Down the Christmas Greeting Page
3.1 Turning a Vague Requirement into an Acceptable Spec
The more your prompt reads like a requirements document, the more stable the output. Below is the structured prompt used in this article; where the font spec was truncated in the original, it has been completed with common web-font conventions. The five-part structure maps each requirement to a checkpoint in the scoring table.
[Requirement] Build a single-page Christmas greeting app[Tech Stack]1. Pure front end: a single HTML file with inline CSS and JavaScript;2. Animations use CSS Animation + requestAnimationFrame;3. No dependency on any external library.[Visual Spec]1. Background: a dark-blue linear gradient transitioning top-to-bottom from #0a1628 to #1a365d;2. Snowflakes: 50 white dots, random diameter 2–5px; falling at a uniform speed with a slight left-right sway;3. Main title: "Merry Christmas" in a serif Western font, gold #FFD700, with a text-shadow glow;4. Subtitle: system sans-serif font, white, 0.85 opacity, at half the title's font size;5. Christmas tree: drawn in pure CSS, three stacked triangles from bottom to top; the bottom layer is 300px wide and 160px tall, and each layer up shrinks both width and height by about 20%, overlapping layer by layer; the trunk is a brown rectangle;6. Lights: 9 dots on the tree, 10px diameter, cycling through red, green, and gold; opacity blinking, random 1–2 second period, phases offset.[Performance Requirements]1. Snowflake animation uses transform rather than top/left to avoid reflow;2. Keep the number of animated elements bounded to guarantee a smooth 60fps.[Responsive Requirements] On narrow screens, the title font size shrinks and the tree scales proportionally.[Output Requirements] Output the complete runnable HTML code directly.
3.2 Snow Particles: Why Prefer Canvas
The spec sets two constraints: “use transform rather than top/left” and “keep the element count bounded to hold 60fps.” There are two common implementation routes:
| Approach | Key Points | Suitable For |
|---|---|---|
| DOM elements + transform | Each snowflake is an absolutely positioned element driven by translate3d, prompting the browser to promote it to a compositing layer | Few particles (dozens), where each element needs its own CSS styling or interaction |
| Per-frame Canvas drawing | Only update particle numeric coordinates, then redraw them all at once inside requestAnimationFrame | Many particles, all changing every frame, saving on style calculations and paint scheduling |
The “uniform fall + slight horizontal sway” requirement actually hints that the second approach is more natural: the vertical position advances linearly by speed, while the horizontal offset adds a sine function. To mimic the sway with the DOM approach, you’d typically stack two animations per element, making both structure and tuning more complex.
Below is the core implementation, with the key points called out in comments:
const canvas = document.getElementById('snow');const ctx = canvas.getContext('2d');const FLAKE_COUNT = 50;let W = 0, H = 0;let flakes = [];function randomBetween(min, max) {return min + Math.random() * (max - min);}function createFlake(initial) {return {x: Math.random() * W,y: initial ? Math.random() * H : -10, // fill the screen initially, then re-enter from the topr: randomBetween(1, 2.5), // diameter 2-5pxvy: randomBetween(30, 60), // vertical speed in px/s, constant => uniform fallamp: randomBetween(6, 16), // horizontal sway amplitudefreq: randomBetween(0.6, 1.4), // sway frequency, adds variationphase: Math.random() * Math.PI * 2, // initial phaset: 0};}function resize() {const dpr = Math.min(window.devicePixelRatio || 1, 2); // cap dpr to balance sharpness and costW = window.innerWidth;H = window.innerHeight;canvas.width = Math.round(W * dpr);canvas.height = Math.round(H * dpr);canvas.style.width = W + 'px';canvas.style.height = H + 'px';ctx.setTransform(dpr, 0, 0, dpr, 0, 0); // logical coordinates stay in CSS pixelsflakes = Array.from({ length: FLAKE_COUNT }, () => createFlake(true));}window.addEventListener('resize', () => {clearTimeout(resizeTimer);resizeTimer = setTimeout(resize, 150); // debounce to avoid repeatedly rebuilding the canvas});let last = performance.now();function draw(now) {// cap per-frame dt at 50ms so there's no "jump" after switching back to the tabconst dt = Math.min((now - last) / 1000, 0.05);last = now;ctx.clearRect(0, 0, W, H);ctx.fillStyle = '#fff';for (const f of flakes) {f.t += dt;f.y += f.vy * dt; // vertical position driven only by speedif (f.y - f.r > H) Object.assign(f, createFlake(false));const sway = Math.sin(f.t * f.freq * Math.PI * 2 + f.phase) * f.amp;ctx.beginPath();ctx.arc(f.x + sway, f.y, f.r, 0, Math.PI * 2);ctx.fill();}rafId = requestAnimationFrame(draw);}function start() {cancelAnimationFrame(rafId);last = performance.now();rafId = requestAnimationFrame(draw);}document.addEventListener('visibilitychange', () => {document.hidden ? cancelAnimationFrame(rafId) : start(); // pause rendering in background tabs});resize();start();
Several easily overlooked details here directly determine the experience:
- Time step in seconds: speed is described in px/s, so you must multiply by the per-frame interval dt to get the displacement. If you write “y += 2 every frame” instead, snowflakes fall twice as fast on a 120Hz screen.
- Cap dt: browsers drastically reduce or even pause requestAnimationFrame in the background. Capping dt prevents snowflakes from teleporting when you switch back.
- Clear with clearRect: clear the entire canvas before each frame’s redraw, or snowflakes leave trailing ghosts.
- Multiply canvas size by dpr: on high-density screens, dots that don’t factor in dpr look blurry and soft.
- Rebuild particles after resize: changing the canvas size clears the frame, and the window dimensions have already changed, so old coordinates are no longer valid.
If you insist on the DOM approach, you can drive transform with an inline CSS variable. The key is to use only transform, and never touch top or left:
.flake {position: absolute;top: -10px;border-radius: 50%;background: #fff;will-change: transform;animation: fall var(--dur) linear infinite;}@keyframes fall {from { transform: translate3d(0, 0, 0); }to { transform: translate3d(var(--drift), calc(100vh + 20px), 0); }}
3.3 Pure-CSS Christmas Tree: Describing Geometry with Custom Properties
There are many ways to draw three triangles plus a trunk. A reliable one is clip-path clipping combined with absolute positioning: no images needed, and CSS variables express each layer’s size as a ratio “relative to the bottom layer,” so changing a single value rescales the whole tree.
<div class="tree" aria-label="Christmas tree"><div class="layer" style="--w:1;--h:1;--b:80px"></div><div class="layer" style="--w:.8;--h:.8;--b:140px"></div><div class="layer" style="--w:.6;--h:.6;--b:200px"></div><div class="trunk"></div><div class="star">★</div><div class="lights"></div></div>
.tree {--tree-w: 300px;--tree-h: 160px;--light-d: 10px;position: relative;width: var(--tree-w);height: calc(var(--tree-h) + var(--b-base, 80px));}.layer {position: absolute;left: 0;bottom: var(--b);width: calc(var(--tree-w) * var(--w));height: calc(var(--tree-h) * var(--h));background: linear-gradient(135deg, #2e8b57, #14532d);clip-path: polygon(50% 0, 100% 100%, 0 100%); /* triangle */}.trunk {position: absolute;left: 50%;bottom: 0;width: 36px;height: 80px;transform: translateX(-50%);background: #8b5a2b;}.star {position: absolute;top: calc(var(--tree-h) + 200px + var(--tree-h) * .6 - 30px);left: 50%;transform: translateX(-50%);font-size: 28px;line-height: 1;color: #FFD700;text-shadow: 0 0 10px rgba(255, 215, 0, .8);}
3.4 Lights: Auto-Positioning Along the Triangle Edges
The most common approach for the lights is to hand-write nine sets of left/top coordinates in CSS. But the moment you change the tree’s dimensions, every coordinate has to be recalculated. A better approach is to let JavaScript compute positions automatically from each triangle’s geometry, so a size change only requires re-placing the lights.
const TREE_W = 300, TREE_H = 160, BASE_B = 80;const LAYERS = [{ w: 1, h: 1, b: 80 },{ w: .8, h: .8, b: 140 },{ w: .6, h: .6, b: 200 }];const COLORS = ['#e53e3e', '#38a169', '#FFD700'];const box = document.querySelector('.tree');const lights = document.querySelector('.lights');function buildLights() {lights.innerHTML = '';LAYERS.forEach((L, i) => {[0.55, 0.8].forEach((t, j) => {const el = document.createElement('i');el.className = 'light';const half = TREE_W * L.w / 2 * t; // half-width of the triangle at this heightconst x = TREE_W / 2 + (i + j) % 2 ? half : -half;const top = BASE_B + TREE_H * L.h * (1 - t);el.style.cssText = `left:${x}px;bottom:${top}px;`+ `background:${COLORS[(i * 2 + j) % 3]};`+ `animation-duration:${(1 + Math.random()).toFixed(2)}s;`+ `animation-delay:${(-Math.random() * 2).toFixed(2)}s;`;lights.appendChild(el);});});}
.lights .light {position: absolute;width: var(--light-d);height: var(--light-d);border-radius: 50%;transform: translate(-50%, 50%); /* center the light on the coordinate point */animation: blink 1.5s ease-in-out infinite;}@keyframes blink {0%, 100% { opacity: .25; }50% { opacity: 1; }}
Two details here are easy to miss:
- Negative delay: set animation-delay to a negative value between 0 and -2 seconds so that the moment the page loads, each light is already at a different blink phase, rather than all lighting up in unison.
- Distinguishing the gold lights: gold is close in tone to the gold star and title and is also brighter against the dark green background, so you can add a warm halo to the gold lights:
.lights .light.gold { box-shadow: 0 0 6px 2px rgba(255, 215, 0, .5); }
3.5 Title, Responsive Behavior, and Accessibility
The title and subtitle together embody the idea of “use relative units instead of media queries.” The font size varies smoothly with viewport width, while the tree scales proportionally from a base size — you just use transform in place of the per-property rewrites you’d need in media queries:
.hero { position: relative; z-index: 1; text-align: center; padding-top: 12vh; }.title {margin: 0;font-family: Georgia, 'Times New Roman', 'Noto Serif CJK SC', 'Songti SC', serif;font-size: clamp(32px, 8vw, 64px); /* base 40px, min 32, max 64 */color: #FFD700;text-shadow: 0 0 10px rgba(255, 215, 0, .8), 0 0 24px rgba(255, 215, 0, .4);}.subtitle {margin: 0;font-family: system-ui, -apple-system, 'Segoe UI', 'Microsoft YaHei', sans-serif;font-size: calc(clamp(32px, 8vw, 64px) / 2); /* half the title font size */color: rgba(255, 255, 255, .85);}@media (max-width: 600px) {.tree { transform: scale(.8); transform-origin: bottom center; }}
Accessibility also deserves an explicit mention in the prompt. Use a semantic h1 for the title, add aria-hidden=”true” to the snowflake canvas so screen readers don’t read it out, and disable animations for users who prefer reduced motion:
@media (prefers-reduced-motion: reduce) {.lights .light, .star { animation: none; }}
const reduceMotion = window.matchMedia('(prefers-reduced-motion: reduce)');function syncMotion() {reduceMotion.matches ? cancelAnimationFrame(rafId) : start();}if (reduceMotion.addEventListener) {reduceMotion.addEventListener('change', syncMotion);}syncMotion();
4. Tasks 2 and 3: What the Harder Scenarios Test
4.1 Physics Engine Implementation
A typical prompt is “implement ball falling and bouncing on a Canvas, with mouse drag-to-throw support.” Differences in model output usually show up in three areas:
- Physics model: is it a “fake physics” that only does uniform falling, or does it correctly implement gravitational acceleration and velocity integration;
- Collision response: is there a restitution coefficient (velocity decay on bounce), ground friction, and a rest threshold. Without a rest threshold, the ball jitters forever at a small amplitude and never settles;
- Time stepping: does it use a fixed-timestep accumulator so physics behavior doesn’t vary with frame rate.
const GRAVITY = 1200; // gravity acceleration, px/s^2const RESTITUTION = 0.6; // restitution, 0-1, higher = bouncierconst FRICTION = 0.98; // horizontal speed retained after each bounceconst SLEEP_V = 20; // speed below this is treated as at restconst STEP = 1 / 120; // fixed 120Hz step, decoupled from the screen refresh ratelet acc = 0, last = performance.now();function frame(now) {acc += Math.min((now - last) / 1000, 0.1);last = now;while (acc >= STEP) {physicsStep(STEP);acc -= STEP;}render();rafId = requestAnimationFrame(frame);}function physicsStep(dt) {for (const b of balls) {b.vy += GRAVITY * dt;b.x += b.vx * dt;b.y += b.vy * dt;if (b.y + b.r > H) { // collide with the groundb.y = H - b.r;b.vy = -b.vy * RESTITUTION;b.vx *= FRICTION;if (Math.abs(b.vy) < SLEEP_V) b.vy = 0; // prevent infinite micro-bouncing}if (b.x - b.r < 0 || b.x + b.r > W) { // collide with the left/right wallsb.vx = -b.vx * RESTITUTION;b.x = Math.max(b.r, Math.min(W - b.r, b.x));}}}
4.2 Scientific Visualization
A typical prompt is something like “use SVG to draw a rose chart showing 12 months of sales data.” The evaluation focuses on four points:
- Separation of data from rendering logic, with the chart driven by configuration;
- Sectors converted from polar coordinates to SVG paths, rather than pieced together from multiple divs;
- Automatic label collision avoidance and formatting of long numbers;
- A text-based legend or summary to preserve accessibility.
This scenario is especially suited to adding “automated data validation” to the scoring table: drive different models’ outputs with the same dataset, then parse the generated SVG and verify one by one that each sector’s arc length is proportional to its value. This is far more objective than eyeballing, and it’s easier to catch the hidden problem of “the chart looks good but the data mapping is wrong.”
function polar(cx, cy, r, angleDeg) {const a = (angleDeg - 90) * Math.PI / 180; // treat 12 o'clock as the 0-degree originreturn [cx + r * Math.cos(a), cy + r * Math.sin(a)];}function sectorPath(cx, cy, r, startDeg, endDeg) {const [x1, y1] = polar(cx, cy, r, startDeg);const [x2, y2] = polar(cx, cy, r, endDeg);const large = endDeg - startDeg > 180 ? 1 : 0;return `M ${cx} ${cy} L ${x1} ${y1} `+ `A ${r} ${r} 0 ${large} 1 ${x2} ${y2} Z`;}function roseChart(values, options = {}) {const { size = 320, maxR = 130, colors = ['#3182ce'] } = options;const cx = size / 2, cy = size / 2;const max = Math.max(...values);const step = 360 / values.length;let paths = '';values.forEach((v, i) => {const r = maxR * v / max; // radius proportional to value — the essence of a rose chartconst d = sectorPath(cx, cy, r, i * step, (i + 1) * step - 1);paths += `<path d="${d}" fill="${colors[i % colors.length]}" `+ `fill-opacity=".85"><title>Month ${i + 1}: ${v}</title></path>`;});return `<svg viewBox="0 0 ${size} ${size}" width="${size}" height="${size}" `+ `role="img" aria-label="Monthly data rose chart">${paths}</svg>`;}
5. From “Looking at the Result” to “Automated Acceptance”
Manual visual inspection is heavily influenced by screen quality and subjective preference, so it’s better to encode the key specs into scripts that run automatically. The illustrative script below covers hard metrics like color, count, animation method, and responsiveness, and can serve directly as part of a regression test:
// Illustrative: run in a browser automation environmentfunction checkSpec(html) {const issues = [];// 1. single-file, zero dependency: no external resource references allowedif (/<(script|link|img)[^>]+(src|href)\s*=\s*["']https?:/i.test(html)) {issues.push('external dependency found');}const doc = new DOMParser().parseFromString(html, 'text/html');// 2. gradient background: colors and direction must both match the specconst bodyBg = getComputedStyle(doc.body).backgroundImage;if (!/linear-gradient/i.test(bodyBg)|| !bodyBg.includes('rgb(10, 22, 40)') // #0a1628|| !bodyBg.includes('rgb(26, 54, 93)')) { // #1a365dissues.push('background gradient mismatch');}// 3. title spec: text, font size, gold color, and glowconst h1 = doc.querySelector('h1');if (!h1 || !/Merry Christmas/i.test(h1.textContent)) issues.push('title missing');const hs = getComputedStyle(h1);if (hs.color !== 'rgb(255, 215, 0)' || hs.textShadow === 'none') {issues.push('title color or glow mismatch');}const px = parseFloat(hs.fontSize);const expected = Math.max(32, Math.min(innerWidth * 0.08, 64));if (Math.abs(px - expected) > 1) issues.push('title font size not responsive to viewport');// 4. snow animation: any CSS animation touching top/left is treated as a violationfor (const sheet of doc.styleSheets) {for (const rule of sheet.cssRules) {if (rule.type === CSSRule.KEYFRAMES_RULE&& /\b(top|left)\b/.test(rule.cssText)) {issues.push('animation property that may trigger reflow');}}}return issues;}
Pair this with a performance-panel recording of a frame timeline to check for long tasks and dropped frames, then take screenshots at three viewports — 375px, 768px, and 1440px — for comparison. Together these produce an objective, reproducible evaluation report.
6. Conclusion: Bring Selection Back to Engineering Standards
Back to the original question: when it comes to writing a Christmas greeting page, which AI is best? Rather than chasing a vague ranking, build your own evaluation system:
- Write requirements clearly with a structured prompt;
- Replace a single impression with a multi-dimensional scoring table;
- Back it up with automated acceptance scripts;
- Continuously regress against a task set drawn from real projects.
Under such a system, each model’s strengths and weaknesses will shift dynamically with scenario and version, but your selection ability and engineering quality stay in your own hands. The complete code given above integrates all the key points — snowflakes, Christmas tree, lights, responsiveness, accessibility, and performance optimization — and can be saved as a single HTML file and opened to run directly, serving as a baseline implementation for your evaluation system.
<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Merry Christmas</title><style>:root {--tree-w: 300px;--tree-h: 160px;--b-base: 80px;--light-d: 10px;}* { margin: 0; padding: 0; box-sizing: border-box; }body {min-height: 100vh;overflow: hidden;color: #fff;background: linear-gradient(#0a1628, #1a365d);}#snow { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; }.hero {position: relative;z-index: 1;text-align: center;padding-top: 12vh;}.title {font-family: Georgia, 'Times New Roman', 'Noto Serif CJK SC', 'Songti SC', serif;font-size: clamp(32px, 8vw, 64px);color: #FFD700;text-shadow: 0 0 10px rgba(255, 215, 0, .8), 0 0 24px rgba(255, 215, 0, .4);}.subtitle {font-family: system-ui, -apple-system, 'Segoe UI', 'Microsoft YaHei', sans-serif;font-size: calc(clamp(32px, 8vw, 64px) / 2);color: rgba(255, 255, 255, .85);}.tree {position: relative;z-index: 1;width: var(--tree-w);height: calc(var(--tree-h) + 200px + var(--tree-h) * .6 + 16px);margin: 40px auto 0;}.layer {position: absolute;left: 0;bottom: var(--b);width: calc(var(--tree-w) * var(--w));height: calc(var(--tree-h) * var(--h));background: linear-gradient(135deg, #2e8b57, #14532d);clip-path: polygon(50% 0, 100% 100%, 0 100%);}.trunk {position: absolute;left: 50%;bottom: 0;width: 36px;height: 80px;transform: translateX(-50%);background: #8b5a2b;}.star {position: absolute;top: 0;left: 50%;transform: translateX(-50%);font-size: 28px;line-height: 1;color: #FFD700;text-shadow: 0 0 10px rgba(255, 215, 0, .8);}.lights .light {position: absolute;width: var(--light-d);height: var(--light-d);border-radius: 50%;transform: translate(-50%, 50%);animation: blink 1.5s ease-in-out infinite;}.lights .light.gold { box-shadow: 0 0 6px 2px rgba(255, 215, 0, .5); }@keyframes blink { 0%, 100% { opacity: .25; } 50% { opacity: 1; } }@media (max-width: 600px) {.tree { transform: scale(.8); transform-origin: top center; }}@media (prefers-reduced-motion: reduce) {.lights .light { animation: none; opacity: 1; }}</style></head><body><canvas id="snow" aria-hidden="true"></canvas><header class="hero"><h1 class="title">Merry Christmas</h1><p class="subtitle">May your code be bug-free. Merry Christmas!</p></header><div class="tree" role="img" aria-label="A Christmas tree with blinking lights"><div class="layer" style="--w:1;--h:1;--b:80px"></div><div class="layer" style="--w:.8;--h:.8;--b:140px"></div><div class="layer" style="--w:.6;--h:.6;--b:200px"></div><div class="trunk"></div><div class="star" aria-hidden="true">★</div><div class="lights" aria-hidden="true"></div></div><script>/* ---------- Snow particles ---------- */const canvas = document.getElementById('snow');const ctx = canvas.getContext('2d');const FLAKE_COUNT = 50;const COLORS = ['#e53e3e', '#38a169', '#FFD700'];const reduceMotion = window.matchMedia('(prefers-reduced-motion: reduce)');let W = 0, H = 0, rafId = 0, last = 0, resizeTimer = 0;let flakes = [];const rand = (min, max) => min + Math.random() * (max - min);function createFlake(initial) {return {x: Math.random() * W,y: initial ? Math.random() * H : -10,r: rand(1, 2.5), // diameter 2-5pxvy: rand(30, 60), // vertical speed in px/s, constantamp: rand(6, 16), // horizontal sway amplitudefreq: rand(0.6, 1.4), // sway frequency in Hzphase: rand(0, Math.PI * 2),t: 0};}function resize() {const dpr = Math.min(window.devicePixelRatio || 1, 2);W = window.innerWidth;H = window.innerHeight;canvas.width = Math.round(W * dpr);canvas.height = Math.round(H * dpr);ctx.setTransform(dpr, 0, 0, dpr, 0, 0);flakes = Array.from({ length: FLAKE_COUNT }, () => createFlake(true));}window.addEventListener('resize', () => {clearTimeout(resizeTimer);resizeTimer = setTimeout(resize, 150);});function draw(now) {const dt = Math.min((now - last) / 1000, 0.05);last = now;ctx.clearRect(0, 0, W, H);ctx.fillStyle = '#fff';for (const f of flakes) {f.t += dt;f.y += f.vy * dt;if (f.y - f.r > H) Object.assign(f, createFlake(false));const sway = Math.sin(f.t * f.freq * Math.PI * 2 + f.phase) * f.amp;ctx.beginPath();ctx.arc(f.x + sway, f.y, f.r, 0, Math.PI * 2);ctx.fill();}rafId = requestAnimationFrame(draw);}function start() {cancelAnimationFrame(rafId);last = performance.now();rafId = requestAnimationFrame(draw);}function syncMotion() {reduceMotion.matches ? cancelAnimationFrame(rafId) : start();}document.addEventListener('visibilitychange', () => {if (document.hidden) {cancelAnimationFrame(rafId);} else if (!reduceMotion.matches) {start();}});if (reduceMotion.addEventListener) {reduceMotion.addEventListener('change', syncMotion);}/* ---------- Tree lights ---------- */function buildLights() {const root = getComputedStyle(document.documentElement);const W0 = parseFloat(root.getPropertyValue('--tree-w'));const H0 = parseFloat(root.getPropertyValue('--tree-h'));const B0 = parseFloat(root.getPropertyValue('--b-base'));const layers = [{ w: 1, h: 1, b: B0 },{ w: .8, h: .8, b: B0 + 60 },{ w: .6, h: .6, b: B0 + 120 }];const box = document.querySelector('.lights');box.innerHTML = '';layers.forEach((L, i) => {[0.55, 0.8].forEach((t, j) => {const el = document.createElement('i');el.className = 'light' + (COLORS[(i * 2 + j) % 3] === '#FFD700' ? ' gold' : '');const half = W0 * L.w / 2 * t;const x = W0 / 2 + ((i + j) % 2 ? half : -half);const bottom = L.b + H0 * L.h * (1 - t);el.style.cssText =`left:${x}px;bottom:${bottom}px;`+ `background:${COLORS[(i * 2 + j) % 3]};`+ `animation-duration:${rand(1, 2).toFixed(2)}s;`+ `animation-delay:${(-rand(0, 2)).toFixed(2)}s;`;box.appendChild(el);});});}/* ---------- Init ---------- */resize();buildLights();syncMotion();</script></body></html>
