Close Menu

    Subscribe to Updates

    Get the latest creative news from FooBar about art, design and business.

    What's Hot

    How to make 3D ASCII Christmas Tree Animation using HTML CSS & JavaScript

    2 December 2026

    How to make Doomsday 3D Card Hover Animation using HTML & CSS

    30 November 2026

    How to make Interactive Wardrobe Rail using HTML CSS & JavaScript

    28 November 2026
    Facebook X (Twitter) Instagram YouTube Telegram Threads
    Coding StellaCoding Stella
    • Home
    • Blog
    • HTML & CSS
      • Login Form
    • JavaScript
    • Hire us!
    Coding StellaCoding Stella
    Home » How to make 3D ASCII Christmas Tree Animation using HTML CSS & JavaScript
    JavaScript

    How to make 3D ASCII Christmas Tree Animation using HTML CSS & JavaScript

    Coding StellaBy Coding Stella2 December 2026Updated:2 December 2026No Comments28 Mins Read
    Share Facebook Twitter Pinterest LinkedIn Tumblr Reddit Email WhatsApp Copy Link

    Let’s create a 3D ASCII Christmas Tree Animation using HTML, CSS, and JavaScript – a rotating Christmas tree made only of text characters, where snow swirls in to build the tree, a golden garland lights up like a fuse, a star slams onto the top, gifts drop and pop open, and “MERRY CHRISTMAS 2026” decodes on the screen.

    • HTML: Create a simple page with one full-screen <canvas> element where the whole ASCII Christmas tree scene is drawn, and load the JetBrains Mono font for the characters.
    • CSS: Style a dark, full-screen background with no scrollbars, and make the canvas fill the whole window on desktop and mobile.
    • JavaScript: Add a small 3D engine that places thousands of points on a cone, rotates and projects them with a depth buffer, turns each point into an ASCII character by brightness, and runs a 20 second timeline with the vortex, lights, ornaments, star, gifts, text and the final explosion.

    This project teaches how to build a 3D ASCII animation using HTML, CSS, and JavaScript by combining 3D point projection, a z-buffer on a character grid, easing functions for smooth motion, and canvas blur layers for a soft glow.

    HTML :

    HTML: Creates the page structure with a single full-screen canvas for the ASCII Christmas tree, links the JetBrains Mono font and the stylesheet, and loads the script.

    <!DOCTYPE html>
    <!--
      ASCII Christmas Tree
      Made by @coding.stella
      © 2026 Coding Stella. All rights reserved.
    -->
    <html lang="en">
    <head>
      <meta charset="UTF-8" />
      <meta name="viewport" content="width=device-width, initial-scale=1.0" />
      <meta name="author" content="@coding.stella" />
      <title>ASCII Christmas Tree | @coding.stella</title>
      <link rel="preconnect" href="https://fonts.googleapis.com" />
      <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
      <link href="https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@500;700&display=swap" rel="stylesheet" />
      <link rel="stylesheet" href="style.css" />
    </head>
    <body>
      <canvas id="scene"></canvas>
    
      <script src="script.js"></script>
    </body>
    </html>

    CSS :

    CSS: Resets the default spacing, sets the dark night background, hides scrollbars, and makes the canvas cover the full screen.

    /*
      ASCII Christmas Tree
      Made by @coding.stella
      © 2026 Coding Stella. All rights reserved.
    */
    
    * {
      margin: 0;
      padding: 0;
      box-sizing: border-box;
    }
    
    html,
    body {
      width: 100%;
      height: 100%;
      overflow: hidden;
      background: #05070f;
      font-family: "JetBrains Mono", ui-monospace, monospace;
      cursor: pointer;
    }
    
    #scene {
      display: block;
      width: 100vw;
      height: 100vh;
    }

    JavaScript:

    JavaScript: Builds the tree, trunk, garland, bulbs, ornaments, 3D star and gift boxes as points, projects them onto an ASCII grid with depth and lighting, and animates the whole show with easing, sparkles, decoding text and a glow effect in a smooth loop.

    /*
      ASCII Christmas Tree
      Made by @coding.stella
      © 2026 Coding Stella. All rights reserved.
    */
    
    const cv = document.getElementById("scene");
    const ctx = cv.getContext("2d");
    const off = document.createElement("canvas");
    const o = off.getContext("2d");
    
    const LOOP = 20;
    const RAMP = ".:-=+*o%#&@";
    const GLYPHS = "!<>-_\\/[]{}=+*^?#%&@$ABCDEFXYZ0123456789";
    const KIND = { FOLIAGE: 0, GARLAND: 1, BULB: 2, ORNAMENT: 3, STAR: 4, GIFT: 5, GROUND: 6 };
    
    const TOP = 1.3;
    const BASE = -0.88;
    const TH = TOP - BASE;
    const R = 0.95;
    const GROUND = -1.24;
    const STAR_Y = TOP + 0.15;
    const CAM = 5;
    
    const clamp = (v, a = 0, b = 1) => (v < a ? a : v > b ? b : v);
    const lerp = (a, b, k) => a + (b - a) * k;
    const frac = (v) => v - Math.floor(v);
    const easeOutCubic = (k) => 1 - Math.pow(1 - k, 3);
    const easeInOutCubic = (k) => (k < 0.5 ? 4 * k * k * k : 1 - Math.pow(-2 * k + 2, 3) / 2);
    const easeOutBack = (k) => 1 + 2.9 * Math.pow(k - 1, 3) + 1.9 * Math.pow(k - 1, 2);
    const easeOutBounce = (k) => {
      const n = 7.5625, d = 2.75;
      if (k < 1 / d) return n * k * k;
      if (k < 2 / d) return n * (k -= 1.5 / d) * k + 0.75;
      if (k < 2.5 / d) return n * (k -= 2.25 / d) * k + 0.9375;
      return n * (k -= 2.625 / d) * k + 0.984375;
    };
    
    function rng(seed) {
      return () => {
        seed = (seed + 0x6d2b79f5) | 0;
        let t = Math.imul(seed ^ (seed >>> 15), 1 | seed);
        t = (t + Math.imul(t ^ (t >>> 7), 61 | t)) ^ t;
        return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
      };
    }
    
    let W, H, DPR, FS, CW, CH, COLS, ROWS, NC, SCALE, CX, CY;
    let zb, L, Hh, Ss, Ll, SOL, ovCh, ovCol, ovA;
    let pts = [], snow = [], textCells = [], giftMeta = [];
    let cosY, sinY, cosX, sinX, zoom;
    
    function resize() {
      DPR = Math.min(devicePixelRatio || 1, 2);
      W = innerWidth;
      H = innerHeight;
      FS = Math.max(8, Math.round(Math.min(H, W * 1.7) / 92));
      CW = FS * 0.6;
      CH = FS * 1.05;
      COLS = Math.ceil(W / CW);
      ROWS = Math.ceil(H / CH);
      NC = COLS * ROWS;
    
      for (const c of [cv, off]) {
        c.width = W * DPR;
        c.height = H * DPR;
      }
    
      zb = new Float32Array(NC);
      L = new Float32Array(NC);
      Hh = new Float32Array(NC);
      Ss = new Float32Array(NC);
      Ll = new Float32Array(NC);
      SOL = new Uint8Array(NC);
      ovCh = new Array(NC);
      ovCol = new Array(NC);
      ovA = new Float32Array(NC);
    
      SCALE = Math.min((H * 0.72) / 2.7, (W * 0.96) / 2.45);
      CX = W / 2;
      CY = H * 0.5;
      build();
    }
    
    function build() {
      const rand = rng(2026);
      const coneR = (u) => R * u * (0.84 + 0.16 * ((u * 6) % 1));
    
      const add = (p) => {
        const a = rand() * Math.PI * 2;
        const rr = 1.8 + rand() * 2.4;
        const len = Math.hypot(p.x, p.y + 0.3, p.z) || 1;
        p.ox = Math.cos(a) * rr;
        p.oy = rand() * 4.4 - 2.2;
        p.oz = Math.sin(a) * rr;
        p.ex = p.x / len + (rand() - 0.5) * 0.8;
        p.ey = (p.y + 0.3) / len + (rand() - 0.2) * 0.8;
        p.ez = p.z / len + (rand() - 0.5) * 0.8;
        p.ph = rand() * 6.28;
        pts.push(p);
      };
    
      pts = [];
      const nTree = buildFoliage(rand, coneR, add);
      buildTrunk(rand, add);
      buildLights(nTree, coneR, add);
      buildOrnaments(rand, coneR, add);
      buildStar(add);
      buildGifts(add);
      buildGround(add);
      buildSnow(rand);
      buildText();
    }
    
    function buildFoliage(rand, coneR, add) {
      const n = Math.round(clamp(NC * 0.6, 4000, 16000));
      for (let i = 0; i < n; i++) {
        const u = Math.sqrt(rand());
        const a = rand() * Math.PI * 2;
        const r = coneR(u) * (0.78 + 0.22 * Math.sqrt(rand()));
        const snowy = rand() < 0.05 && r > coneR(u) * 0.93;
        add({
          kind: KIND.FOLIAGE,
          x: Math.cos(a) * r, y: TOP - u * TH, z: Math.sin(a) * r,
          h: snowy ? 200 : 112 + rand() * 32,
          s: snowy ? 15 : 55 + rand() * 25,
          l: snowy ? 92 : 34 + rand() * 22,
          b: 0.7 + rand() * 0.3,
          d: (1 - u) * 1.4 + rand() * 0.5,
        });
      }
      return n;
    }
    
    function buildTrunk(rand, add) {
      const n = Math.round(clamp(NC * 0.05, 700, 1800));
      for (let i = 0; i < n; i++) {
        const a = rand() * Math.PI * 2;
        const y = GROUND + rand() * (BASE - GROUND + 0.3);
        const below = clamp((BASE - y) / (BASE - GROUND));
        const r = 0.12 + 0.05 * below * below;
        const groove = Math.sin(y * 70 + a * 3) > 0.6;
        add({
          kind: KIND.FOLIAGE,
          x: Math.cos(a) * r, y, z: Math.sin(a) * r,
          h: 22 + rand() * 8, s: 50 + rand() * 15, l: groove ? 22 : 30 + rand() * 14,
          b: 0.8 + rand() * 0.2,
          d: rand() * 0.4,
        });
      }
    }
    
    function buildLights(nTree, coneR, add) {
      const turns = 6.5;
      const nGarland = Math.round(nTree * 0.16);
      for (let i = 0; i < nGarland; i++) {
        const s = i / nGarland, u = 0.06 + s * 0.94, a = s * turns * Math.PI * 2, r = coneR(u) * 1.04;
        add({ kind: KIND.GARLAND, s, x: Math.cos(a) * r, y: TOP - u * TH, z: Math.sin(a) * r, h: 46, s2: 95, l: 62, b: 1, d: (1 - u) * 1.4 });
      }
    
      const hues = [0, 45, 210, 130, 300, 25];
      const nBulbs = 110;
      for (let i = 0; i < nBulbs; i++) {
        const s = i / nBulbs, u = 0.1 + s * 0.9, a = s * turns * Math.PI * 2 + Math.PI, r = coneR(u) * 1.05;
        add({ kind: KIND.BULB, s, x: Math.cos(a) * r, y: TOP - u * TH, z: Math.sin(a) * r, h: hues[i % hues.length], l: 62, b: 1, d: (1 - u) * 1.4 });
      }
    }
    
    function buildOrnaments(rand, coneR, add) {
      const colors = [[355, 90, 58], [355, 90, 58], [46, 95, 60], [210, 90, 65], [0, 0, 92]];
      for (let k = 0; k < 30; k++) {
        const u = 0.22 + rand() * 0.75, a = rand() * Math.PI * 2, r = coneR(u) * 1.02;
        const rad = 0.03 + rand() * 0.022;
        const [h, s, l] = colors[k % colors.length];
        const d = 5.6 + rand() * 1.6;
        const n = 26;
        for (let i = 0; i < n; i++) {
          const yy = 1 - (i / (n - 1)) * 2, rr = Math.sqrt(1 - yy * yy), th = i * 2.39996;
          add({
            kind: KIND.ORNAMENT,
            x: Math.cos(a) * r, y: TOP - u * TH, z: Math.sin(a) * r,
            qx: Math.cos(th) * rr * rad, qy: yy * rad, qz: Math.sin(th) * rr * rad,
            h, s2: s, l: i < 3 ? 96 : l, b: 0.7 + 0.3 * yy, d, pd: (1 - u) * 1.4,
          });
        }
      }
    }
    
    function buildStar(add) {
      const poly = [];
      for (let i = 0; i < 10; i++) {
        const rr = i % 2 ? 0.08 : 0.19, a = -Math.PI / 2 + (i * Math.PI) / 5;
        poly.push([Math.cos(a) * rr, Math.sin(a) * rr]);
      }
      const inside = (x, y) => {
        let c = false;
        for (let i = 0, j = poly.length - 1; i < poly.length; j = i++) {
          const [xi, yi] = poly[i], [xj, yj] = poly[j];
          if (yi > y !== yj > y && x < ((xj - xi) * (y - yi)) / (yj - yi) + xi) c = !c;
        }
        return c;
      };
    
      const depth = 0.03;
      for (let x = -0.2; x <= 0.2; x += 0.007)
        for (let y = -0.2; y <= 0.2; y += 0.007) {
          if (!inside(x, y)) continue;
          for (const face of [-1, 1])
            add({ kind: KIND.STAR, x: 0, y: STAR_Y, z: 0, qx: x, qy: -y, qz: face * depth, face, core: 1 - Math.hypot(x, y) / 0.19, h: 46, s2: 100, l: 60, b: 1 });
        }
    
      for (let i = 0; i < poly.length; i++) {
        const [x0, y0] = poly[i], [x1, y1] = poly[(i + 1) % poly.length];
        for (let k = 0; k <= 1; k += 0.04)
          for (let z = -depth; z <= depth; z += 0.013)
            add({ kind: KIND.STAR, x: 0, y: STAR_Y, z: 0, qx: lerp(x0, x1, k), qy: -lerp(y0, y1, k), qz: z, face: 0, core: 0, h: 34, s2: 100, l: 45, b: 0.85 });
      }
    }
    
    function buildGifts(add) {
      const gifts = [
        { a: 0.45, w: 0.34, h: 0.26, d: 0.3, c: [355, 85, 48], rb: [46, 95, 60], pat: "none" },
        { a: 1.6, w: 0.26, h: 0.36, d: 0.26, c: [220, 80, 52], rb: [0, 0, 96], pat: "dots", pc: [0, 0, 96] },
        { a: 2.9, w: 0.38, h: 0.2, d: 0.3, c: [280, 65, 50], rb: [46, 95, 62], pat: "stripes", pc: [290, 75, 72] },
        { a: 4.15, w: 0.28, h: 0.25, d: 0.28, c: [0, 0, 94], rb: [355, 85, 52], pat: "stripes", pc: [355, 85, 52] },
        { a: 5.3, w: 0.32, h: 0.22, d: 0.3, c: [40, 90, 52], rb: [355, 85, 52], pat: "dots", pc: [355, 85, 55] },
        { a: 5.3, w: 0.18, h: 0.15, d: 0.18, c: [0, 0, 94], rb: [215, 85, 58], pat: "none", on: 4 },
      ];
      const ringR = 0.9;
      const step = 0.013;
      giftMeta = [];
    
      gifts.forEach((G, gi) => {
        const stacked = G.on !== undefined;
        const cx = Math.cos(G.a) * ringR, cz = Math.sin(G.a) * ringR;
        const y0 = GROUND + (stacked ? gifts[G.on].h : 0);
        const yaw = G.a * 1.7 + gi, ca = Math.cos(yaw), sa = Math.sin(yaw);
        const drop = 8.6 + gi * 0.22 + (stacked ? 0.5 : 0);
        const pop = 10.6 + gi * 0.32;
        const lidH = Math.min(0.06, G.h * 0.28);
        const rw = Math.min(G.w, G.d) * 0.085;
        const hw = G.w / 2, hd = G.d / 2, body = G.h - lidH;
        const lw = hw + 0.012, ld = hd + 0.012;
        giftMeta.push({ x: cx, y: y0 + G.h, z: cz, pop, seed: gi * 7.31 });
    
        const paper = (u, v) => {
          if (G.pat === "dots") {
            const row = Math.floor(v / 0.05);
            const fu = frac(u / 0.05 + (row % 2) * 0.5) - 0.5, fv = frac(v / 0.05) - 0.5;
            return fu * fu + fv * fv < 0.07 ? G.pc : G.c;
          }
          if (G.pat === "stripes") return Math.sin((u + v) * 52) > 0.35 ? G.pc : G.c;
          return G.c;
        };
    
        const P = (lx, ly, lz, nx, ny, nz, [h, s, l], part, edge) =>
          add({
            kind: KIND.GIFT, part, pop, edge,
            x: cx + lx * ca - lz * sa, y: y0 + ly, z: cz + lx * sa + lz * ca,
            nx: nx * ca - nz * sa, ny, nz: nx * sa + nz * ca,
            h, s2: s, l, b: 0.92, d: drop,
          });
    
        for (let y = 0; y <= body; y += step) {
          for (let x = -hw; x <= hw; x += step) {
            const c = Math.abs(x) < rw ? G.rb : paper(x, y);
            const e = Math.abs(Math.abs(x) - hw) < step * 0.6;
            P(x, y, -hd, 0, 0, -1, c, "body", e);
            P(x, y, hd, 0, 0, 1, c, "body", e);
          }
          for (let z = -hd; z <= hd; z += step) {
            const c = Math.abs(z) < rw ? G.rb : paper(z, y);
            P(-hw, y, z, -1, 0, 0, c, "body", false);
            P(hw, y, z, 1, 0, 0, c, "body", false);
          }
        }
    
        for (let y = body; y <= G.h; y += step) {
          const e = y + step > G.h || y - step < body;
          for (let x = -lw; x <= lw; x += step) {
            const c = Math.abs(x) < rw ? G.rb : G.c;
            P(x, y, -ld, 0, 0, -1, c, "lid", e);
            P(x, y, ld, 0, 0, 1, c, "lid", e);
          }
          for (let z = -ld; z <= ld; z += step) {
            const c = Math.abs(z) < rw ? G.rb : G.c;
            P(-lw, y, z, -1, 0, 0, c, "lid", e);
            P(lw, y, z, 1, 0, 0, c, "lid", e);
          }
        }
    
        for (let x = -lw; x <= lw; x += step)
          for (let z = -ld; z <= ld; z += step) {
            const c = Math.abs(x) < rw || Math.abs(z) < rw ? G.rb : paper(x, z);
            const e = Math.abs(Math.abs(x) - lw) < step * 0.6 || Math.abs(Math.abs(z) - ld) < step * 0.6;
            P(x, G.h, z, 0, 1, 0, c, "lid", e);
          }
    
        const bs = clamp(Math.min(G.w, G.d) / 0.3, 0.6, 1.1);
        for (const side of [-1, 1]) {
          for (let i = 0; i < 30; i++) {
            const a = (i / 30) * Math.PI * 2;
            for (let j = 0; j < 6; j++) {
              const b = (j / 6) * Math.PI * 2;
              const ox = side * (0.045 + Math.cos(a) * 0.04) * bs;
              const oy = (0.04 + Math.sin(a) * 0.03) * bs + Math.cos(b) * 0.008;
              const oz = Math.sin(b) * 0.012 * bs + side * 0.01;
              P(ox, G.h + oy, oz, side * Math.cos(a), Math.sin(a), Math.sin(b), G.rb, "lid", false);
            }
          }
          for (let k = 0; k <= 1; k += 0.08)
            for (let wv = -0.012; wv <= 0.012; wv += 0.008)
              P(side * k * 0.07 * bs + wv, G.h + 0.006, side * k * 0.08 * bs, 0, 1, 0, G.rb, "lid", false);
        }
    
        for (let i = 0; i < 24; i++) {
          const yy = 1 - (i / 23) * 2, rr = Math.sqrt(1 - yy * yy), th = i * 2.39996;
          P(
            Math.cos(th) * rr * 0.02 * bs, G.h + (0.025 + yy * 0.02) * bs, Math.sin(th) * rr * 0.02 * bs,
            Math.cos(th) * rr, yy, Math.sin(th) * rr, G.rb, "lid", true
          );
        }
      });
    }
    
    function buildGround(add) {
      for (let ring = 0; ring < 18; ring++) {
        const rr = 0.35 + ring * 0.13, n = Math.round(rr * 70);
        for (let i = 0; i < n; i++) {
          const a = (i / n) * Math.PI * 2 + ring * 0.3;
          add({ kind: KIND.GROUND, x: Math.cos(a) * rr, y: GROUND, z: Math.sin(a) * rr, h: 215, s2: 30, l: 70, b: 0.35 * (1 - ring / 20) });
        }
      }
    }
    
    function buildSnow(rand) {
      snow = [];
      for (let i = 0; i < 420; i++)
        snow.push({ x: rand() * 7 - 3.5, y: rand() * 5 - 2.5, z: rand() * 6 - 3, v: 0.15 + rand() * 0.35, ph: rand() * 6.28 });
    }
    
    function buildText() {
      const lines = [["M E R R Y   C H R I S T M A S", "#ff4d5e"], ["2 0 2 6", "#ffd84a"]];
      const baseRow = Math.min(ROWS - 4, Math.round((CY + 1.62 * SCALE) / CH));
      textCells = [];
      let idx = 0;
      lines.forEach(([str, color], li) => {
        const c0 = Math.floor(COLS / 2 - str.length / 2);
        [...str].forEach((ch, i) => {
          if (ch === " ") return;
          textCells.push({ c: c0 + i, r: baseRow + li * 2, ch, color, t0: 9.4 + idx * 0.025, t1: 9.9 + idx * 0.07 + li * 0.4 });
          idx++;
        });
      });
    }
    
    function project(x, y, z, spin) {
      let X = x, Z = z;
      if (spin) {
        X = x * cosY - z * sinY;
        Z = x * sinY + z * cosY;
      }
      const Y = y * cosX - Z * sinX;
      const Z2 = y * sinX + Z * cosX;
      const k = (CAM / (Z2 + CAM)) * SCALE * zoom;
      return [CX + X * k, CY - Y * k, Z2];
    }
    
    function splat(px, py, z, lum, h, s, l, solid = 0) {
      const c = (px / CW) | 0, r = (py / CH) | 0;
      if (c < 0 || r < 0 || c >= COLS || r >= ROWS) return;
      const i = r * COLS + c;
      if (z < zb[i]) {
        zb[i] = z; L[i] = lum; Hh[i] = h; Ss[i] = s; Ll[i] = l; SOL[i] = solid;
      }
    }
    
    function overlay(c, r, ch, color, a) {
      if (c < 0 || r < 0 || c >= COLS || r >= ROWS) return;
      const i = r * COLS + c;
      ovCh[i] = ch; ovCol[i] = color; ovA[i] = a;
    }
    
    const depthShade = (z) => clamp(0.3 + 0.7 * (1 - (z + 1.1) / 2.2));
    
    function drawPoints(t, S) {
      const fuse = clamp((t - 4) / 2.2);
      const bulbs = clamp((t - 4.6) / 2.0);
    
      for (const p of pts) {
        let x = p.x, y = p.y, z = p.z, lum = p.b, h = p.h, s = p.s2 ?? p.s, l = p.l, spin = true;
    
        if (p.kind <= KIND.ORNAMENT) {
          const a = easeInOutCubic(clamp((t - 0.2 - (p.pd ?? p.d)) / 1.6));
          if (a < 1) {
            const sw = (1 - a) * 4.5, cs = Math.cos(sw), sn = Math.sin(sw);
            const lx = lerp(p.ox, x, a), lz = lerp(p.oz, z, a);
            x = lx * cs - lz * sn;
            z = lx * sn + lz * cs;
            y = lerp(p.oy, y, a);
            s = lerp(10, s, a);
            l = lerp(88, l, a);
            lum = lerp(0.35, lum, a);
          }
    
          if (p.kind === KIND.FOLIAGE) {
            lum *= 0.85 + 0.15 * Math.sin(t * 2.2 + p.ph);
          } else if (p.kind === KIND.GARLAND) {
            if (a < 1 || 1 - p.s > fuse) continue;
            if (fuse < 1 && Math.abs(1 - p.s - fuse) < 0.02) {
              h = 40; s = 100; l = 95; lum = 1;
            } else {
              lum = 0.55 + 0.45 * Math.sin(p.s * 110 - t * 9);
            }
          } else if (p.kind === KIND.BULB) {
            if (a < 1 || 1 - p.s > bulbs) continue;
            h = (p.h + t * 40) % 360;
            s = 95;
            lum = 0.45 + 0.55 * (0.5 + 0.5 * Math.sin(t * 5 + p.ph * 3));
          } else {
            if (t < p.d) continue;
            const k = easeOutBack(clamp((t - p.d) / 0.5));
            x += p.qx * k; y += p.qy * k; z += p.qz * k;
            if (t - p.d < 0.12) { l = 95; s = 0; }
          }
        } else if (p.kind === KIND.STAR) {
          if (t < 7.5) continue;
          const spinIn = easeOutCubic(clamp((t - 7.5) / 0.8));
          const k = 1 + 3 * (1 - easeOutCubic(clamp((t - 7.5) / 0.55)));
          const sa = Math.sin(t * 1.1) * 0.3 + (1 - spinIn) * Math.PI * 4;
          const c = Math.cos(sa), sn = Math.sin(sa);
          x = (p.qx * c - p.qz * sn) * k;
          z = (p.qx * sn + p.qz * c) * k;
          y = STAR_Y + p.qy * k;
          spin = false;
          s = 100;
          if (p.face) {
            const facing = Math.max(0, -p.face * c);
            const core = Math.pow(p.core, 1.4);
            lum = 0.72 + 0.2 * facing + 0.08 * core + 0.05 * Math.sin(t * 4);
            h = 36 + 14 * core;
            l = 52 + 36 * core;
          } else {
            lum = 0.7;
          }
        } else if (p.kind === KIND.GIFT) {
          if (t < p.d) continue;
          y += (1 - easeOutBounce(clamp((t - p.d) / 0.95))) * 3;
          if (p.part === "lid") {
            const k = (t - p.pop) / 0.8;
            if (k > 0 && k < 1)
              y += k < 0.75 ? Math.sin((Math.PI * k) / 0.75) * 0.22 : Math.sin((Math.PI * (k - 0.75)) / 0.25) * 0.025;
          }
          const nx1 = p.nx * cosY - p.nz * sinY, nz1 = p.nx * sinY + p.nz * cosY;
          const ny2 = p.ny * cosX - nz1 * sinX, nz2 = p.ny * sinX + nz1 * cosX;
          const light = Math.max(0, -0.35 * nx1 + 0.75 * ny2 - 0.55 * nz2);
          lum = p.b * (0.62 + 0.38 * light);
          if (p.edge) {
            lum = Math.min(1, lum + 0.3);
            l = Math.min(96, l + 18);
          }
        } else if (p.kind === KIND.GROUND) {
          lum *= clamp(t / 2);
        }
    
        if (S.boom > 0) {
          const d = S.boomE * 4.5;
          x += p.ex * d; y += p.ey * d; z += p.ez * d;
          lum *= S.fade;
          if (lum < 0.02) continue;
        }
    
        const [px, py, pz] = project(x, y, z, spin);
        const solid = p.kind === KIND.GIFT || p.kind === KIND.STAR;
        const sh = p.kind === KIND.STAR ? 1 : p.kind === KIND.GIFT ? 0.8 + 0.2 * depthShade(pz) : depthShade(pz);
        splat(px, py, p.kind === KIND.GROUND ? pz + 5 : pz, lum * sh, h, s, l, solid ? 1 : 0);
      }
    }
    
    function drawSnow(t, dt) {
      for (const f of snow) {
        f.y -= f.v * dt;
        f.x += Math.sin(t * 0.7 + f.ph) * 0.05 * dt;
        if (f.y < -2.6) {
          f.y = 2.6;
          f.x = Math.random() * 7 - 3.5;
        }
        const [px, py, pz] = project(f.x, f.y, f.z, false);
        const near = clamp(1 - (pz + 3) / 6);
        const tw = 0.6 + 0.4 * Math.sin(t * 3 + f.ph * 7);
        splat(px, py, pz + 10, (0.15 + 0.35 * near) * tw, 210, 20, 90);
      }
    }
    
    function drawShockwave(t, sx, sy) {
      const wave = (t - 7.5) / 1.1;
      if (wave <= 0 || wave >= 1) return;
      const rad = easeOutCubic(wave) * Math.max(W, H) * 0.7;
      const thick = CH * 0.9;
      const c0 = Math.max(0, ((sx - rad - thick) / CW) | 0), c1 = Math.min(COLS - 1, ((sx + rad + thick) / CW) | 0);
      const r0 = Math.max(0, ((sy - rad - thick) / CH) | 0), r1 = Math.min(ROWS - 1, ((sy + rad + thick) / CH) | 0);
      for (let r = r0; r <= r1; r++)
        for (let c = c0; c <= c1; c++) {
          const d = Math.abs(Math.hypot(c * CW - sx, r * CH - sy) - rad);
          if (d < thick) overlay(c, r, d < thick * 0.4 ? "*" : "·", "#ffd86b", 0.55 * (1 - wave) * (1 - d / thick));
        }
    }
    
    function drawStarRays(t, sx, sy, fade) {
      if (t <= 7.7) return;
      const ra = clamp((t - 7.7) / 0.6) * fade;
      const unit = SCALE * zoom;
    
      for (let i = 0; i < 12; i++) {
        const ang = t * 0.25 + (i * Math.PI) / 6;
        const size = [0.55, 0.33, 0.26][i % 3];
        const len = unit * size * (0.8 + 0.2 * Math.sin(t * 3 + i * 1.3));
        const dx = Math.cos(ang), dy = Math.sin(ang);
        for (let d = unit * 0.2; d < len; d += CW * 0.8) {
          const c = ((sx + dx * d) / CW) | 0, r = ((sy + dy * d) / CH) | 0;
          if (c < 0 || r < 0 || c >= COLS || r >= ROWS || L[r * COLS + c] > 0.12) continue;
          const fall = 1 - d / len;
          overlay(c, r, fall > 0.65 ? "+" : fall > 0.3 ? "·" : ".", "#ffe08a", ra * fall);
        }
      }
    
      for (let i = 0; i < 14; i++) {
        const a = t * 1.5 + (i * Math.PI * 2) / 14;
        const [px, py] = project(Math.cos(a) * 0.3, STAR_Y + Math.sin(a * 2 + i) * 0.04, Math.sin(a) * 0.3, false);
        const tw = 0.5 + 0.5 * Math.sin(t * 8 + i * 1.7);
        if (tw > 0.35) overlay((px / CW) | 0, (py / CH) | 0, tw > 0.8 ? "*" : "+", "#fff2b8", ra * tw);
      }
    }
    
    function drawGiftBursts(t, fade) {
      const unit = SCALE * zoom;
      for (const g of giftMeta) {
        const k = t - g.pop;
        if (k < 0 || k > 1.4) continue;
        const [px, py] = project(g.x, g.y + 0.05, g.z, true);
        for (let i = 0; i < 26; i++) {
          const f1 = frac(Math.sin(i * 12.9898 + g.seed * 78.233) * 43758.5453);
          const f2 = frac(Math.sin(i * 39.346 + g.seed * 11.135) * 24634.6345);
          const ang = -Math.PI / 2 + (f1 - 0.5) * 2;
          const sp = (0.5 + f2 * 0.9) * unit * 0.9;
          const x = px + Math.cos(ang) * sp * k;
          const y = py + Math.sin(ang) * sp * k + unit * 0.9 * k * k;
          overlay((x / CW) | 0, (y / CH) | 0, "*+·"[i % 3], i % 4 === 0 ? "#ffffff" : "#ffd86b", (1 - k / 1.4) * fade);
        }
      }
    }
    
    function drawText(t, S) {
      for (const tc of textCells) {
        if (t < tc.t0) continue;
        const locked = t >= tc.t1;
        const ch = locked ? tc.ch : GLYPHS[(Math.random() * GLYPHS.length) | 0];
        const a = (locked ? 1 : 0.6) * S.fade * (1 - S.boom);
        const r = tc.r + (S.boom > 0 ? Math.round(S.boomE * 6 * ((tc.c % 3) - 1)) : 0);
        overlay(tc.c, r, ch, locked ? tc.color : "#7dffa0", a);
      }
    }
    
    function paintCells() {
      o.setTransform(DPR, 0, 0, DPR, 0, 0);
      o.clearRect(0, 0, W, H);
      o.font = `700 ${FS}px "JetBrains Mono", ui-monospace, monospace`;
      o.textBaseline = "top";
      const RL = RAMP.length;
    
      for (let i = 0; i < NC; i++) {
        const x = (i % COLS) * CW, y = ((i / COLS) | 0) * CH;
        if (ovCh[i] !== undefined) {
          o.globalAlpha = ovA[i];
          o.fillStyle = ovCol[i];
          o.fillText(ovCh[i], x, y);
          continue;
        }
        const lum = L[i];
        if (lum < 0.03) continue;
        const li = SOL[i] ? RL - 4 + Math.min(3, (lum * 4) | 0) : Math.min(RL - 1, (lum * RL) | 0);
        o.globalAlpha = 1;
        o.fillStyle = `hsl(${Hh[i] | 0},${Ss[i] | 0}%,${(Ll[i] * (0.35 + 0.75 * lum)) | 0}%)`;
        o.fillText(RAMP[li], x, y);
      }
      o.globalAlpha = 1;
    }
    
    function radial(x, y, radius, inner, outer) {
      const g = ctx.createRadialGradient(x * DPR, y * DPR, 0, x * DPR, y * DPR, radius * DPR);
      g.addColorStop(0, inner);
      g.addColorStop(1, outer);
      ctx.fillStyle = g;
      ctx.fillRect(0, 0, cv.width, cv.height);
    }
    
    function composite(t, sx, sy, fade) {
      ctx.setTransform(1, 0, 0, 1, 0, 0);
      ctx.fillStyle = "#03050b";
      ctx.fillRect(0, 0, cv.width, cv.height);
    
      radial(CX, CY, H * 0.6, `rgba(40,140,80,${0.16 * clamp(t / 4) * fade})`, "rgba(0,0,0,0)");
      if (t > 7.5) {
        const glow = clamp((t - 7.5) / 0.4) * fade * (0.85 + 0.15 * Math.sin(t * 3));
        radial(sx, sy, H * 0.35, `rgba(255,210,90,${0.22 * glow})`, "rgba(0,0,0,0)");
      }
    
      ctx.globalCompositeOperation = "lighter";
      ctx.filter = `blur(${FS * 1.8 * DPR}px)`;
      ctx.globalAlpha = 0.75;
      ctx.drawImage(off, 0, 0);
      ctx.filter = `blur(${FS * 0.45 * DPR}px)`;
      ctx.globalAlpha = 0.85;
      ctx.drawImage(off, 0, 0);
      ctx.filter = "none";
      ctx.globalAlpha = 1;
      ctx.globalCompositeOperation = "source-over";
      ctx.drawImage(off, 0, 0);
    
      const flash = t > 7.5 ? 1 - clamp((t - 7.5) / 0.6) : 0;
      if (flash > 0) radial(sx, sy, Math.max(W, H), `rgba(255,235,170,${0.32 * flash * flash})`, "rgba(255,220,150,0)");
    
      const g = ctx.createRadialGradient(cv.width / 2, cv.height * 0.45, cv.height * 0.2, cv.width / 2, cv.height / 2, cv.height * 0.85);
      g.addColorStop(0, "rgba(0,0,0,0)");
      g.addColorStop(1, "rgba(0,0,0,0.6)");
      ctx.fillStyle = g;
      ctx.fillRect(0, 0, cv.width, cv.height);
    }
    
    function render(t, dt) {
      zb.fill(1e9);
      L.fill(0);
      ovCh.fill(undefined);
    
      const boom = clamp((t - 17.2) / 2.3);
      const S = { boom, boomE: boom * boom, fade: 1 - clamp((boom - 0.1) / 0.6) };
    
      const rotY = t * 0.55 - (1 - easeOutCubic(clamp(t / 3.6))) * 5;
      const rotX = 0.27 + 0.04 * Math.sin(t * 0.6);
      cosY = Math.cos(rotY); sinY = Math.sin(rotY);
      cosX = Math.cos(rotX); sinX = Math.sin(rotX);
    
      const slam = t > 7.5 ? 1 - clamp((t - 7.5) / 0.35) : 0;
      zoom = (0.72 + 0.28 * easeOutCubic(clamp(t / 4.5))) * (1 + 0.025 * Math.sin(t * 0.9)) * (1 + slam * 0.04) * (1 + S.boomE * 0.25);
    
      drawPoints(t, S);
      drawSnow(t, dt);
    
      const [sx, sy] = project(0, STAR_Y, 0, false);
      drawShockwave(t, sx, sy);
      drawStarRays(t, sx, sy, S.fade);
      drawGiftBursts(t, S.fade);
      drawText(t, S);
    
      paintCells();
      composite(t, sx, sy, S.fade);
    }
    
    let clock = 0;
    let last = performance.now();
    let paused = false;
    
    const frozen = new URLSearchParams(location.search).get("t");
    if (frozen !== null) {
      clock = parseFloat(frozen) || 0;
      paused = true;
    }
    
    function frame(now) {
      requestAnimationFrame(frame);
      const dt = Math.min(0.05, (now - last) / 1000);
      last = now;
      if (!paused) clock += dt;
      render(clock % LOOP, paused ? 0 : dt);
    }
    
    addEventListener("resize", resize);
    addEventListener("click", () => (clock = 0));
    addEventListener("keydown", (e) => {
      if (e.code === "Space") {
        e.preventDefault();
        paused = !paused;
      }
      if (e.key === "r" || e.key === "R") clock = 0;
    });
    
    resize();
    requestAnimationFrame(frame);

    This project demonstrates how HTML, CSS, and JavaScript can work together to turn plain text characters into a real 3D Christmas scene. You learned how to project 3D points onto a character grid, keep the right object in front with a depth buffer, shade faces with simple lighting, and time many small animations into one smooth loop. Try changing the colours, the number of ornaments or the message to make your own festive ASCII Christmas tree.

    If your project has problems, don’t worry. Just click to download the source code and face your coding challenges with excitement. Have fun coding!

    Animation tree
    Share. Copy Link Twitter Facebook LinkedIn Email WhatsApp
    Previous ArticleHow to make Doomsday 3D Card Hover Animation using HTML & CSS
    Coding Stella
    • Website

    Related Posts

    JavaScript

    How to make Doomsday 3D Card Hover Animation using HTML & CSS

    30 November 2026
    JavaScript

    How to make Interactive Wardrobe Rail using HTML CSS & JavaScript

    28 November 2026
    JavaScript

    How to make Shredder Delete Button using HTML CSS & JavaScript

    23 November 2026
    Add A Comment
    Leave A Reply Cancel Reply

    Trending Post

    Master Frontend in 100 Days Ebook

    2 March 202432K Views

    How to make Modern Login Form using HTML & CSS | Glassmorphism

    11 January 202431K Views

    How to make I love you Animation in HTML CSS & JavaScript

    14 February 202424K Views

    How to make Valentine’s Day Card using HTML & CSS

    13 February 202415K Views
    Follow Us
    • Instagram
    • Facebook
    • YouTube
    • Twitter
    Featured Post

    How to create Animated Firework Diwali using HTML CSS and JS

    16 October 2025

    How to make Animated Login Form with Glowing Input using HTML & CSS

    1 January 2026

    Frontend Developer Roadmap 2025: The Complete Guide

    31 January 2025

    How to make Awesome Search Bar 2 using HTML & CSS

    4 April 2025

    How to make 3D ASCII Christmas Tree Animation using HTML CSS & JavaScript

    2 December 2026

    How to make Doomsday 3D Card Hover Animation using HTML & CSS

    30 November 2026

    How to make Interactive Wardrobe Rail using HTML CSS & JavaScript

    28 November 2026

    How to make Shredder Delete Button using HTML CSS & JavaScript

    23 November 2026
    Facebook X (Twitter) Instagram YouTube
    • About Us
    • Privacy Policy
    • Return and Refund Policy
    • Terms and Conditions
    • Contact Us
    • Buy me a coffee
    © 2026 Coding Stella. Made with 💙 by @coding.stella

    Type above and press Enter to search. Press Esc to cancel.