A square pyramid turning slowly above its shadow, each sandstone face lit flat with bright edges.
╱╲
╱╱@@╲
╱╱@@@@╲╲╲
╱╱@@@@@@@@╲╲
╱@@@@@@@@@@@╲╲
╱@@@@@@@@@@@@@@╲╲╲
╱╱@@@@@@@@@@@@@@@@@╲╲
╱╱@@@@@@@@@@@@@@@@@@@╲╲╲
╱╱@@@@@@@@@@@@@@@@@@@@@@╲╲=╲
╱╱@@@@@@@@@@@@@@@@@@@@@@@@@@╲=╲
╱╱@@@@@@@@@@@@@@@@@@@@@@@@@@@@@╲=╲
╱╱@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@╲=╲
╱╱╱@@@@@@@@@@@@@@@@@──────────────────╲=╲
╱─────────────────────===================╲=╲
───======================================╲╲╲
───===================================╲╲╲
───=======================─────────╲=
░░────────────░░░░░░░░░░░░
░░░░░░░░░▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒░░░░░░░░░
░░░░░░░░▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒░░░░░░░░
░░░░░░░░░░░▒▒▒▒▒▒▒▒▒▒▒▒░░░░░░░░░░░
░░░░░░░░░░░░░░
Paste two lines into any page, use it from React, play it in a terminal, put a GIF in a README, or hand the Agent prompt to your coding agent. Every tab follows the look you pick above.
<script type="module" src="https://www.ascii-magic.com/ascii/ascii.js"></script>
<ascii-art piece="pyramid"></ascii-art>// npm install ascii-magic-art
import { useEffect, useRef } from "react";
import { play } from "ascii-magic-art/runtime/player.js";
import * as piece from "ascii-magic-art/pieces/pyramid.js";
export function Pyramid() {
const ref = useRef(null);
// play() draws the piece on a canvas in your look and returns stop(), which React runs on unmount
useEffect(() => play(ref.current, piece), []);
return <pre ref={ref} style={{ fontSize: 10, fontFamily: "Menlo, Consolas, monospace" }} />;
}npx ascii-magic-art pyramid<!-- Export the GIF below in the look you picked, commit it, then: -->
<p align="center">
<img src="assets/pyramid.gif" alt="Pyramid, animated ASCII art" width="720">
</p>Add the animated ASCII art piece "pyramid" (Pyramid) from ASCII Magic to this project.
1. Load the script once, in the browser only (in SSR frameworks such as Next.js, load it on the client):
<script type="module" src="https://www.ascii-magic.com/ascii/ascii.js"></script>
2. Put the piece where it fits best, such as the hero, a loading state, an empty state or the 404 page:
<ascii-art piece="pyramid"></ascii-art>
3. Keep a real heading or text next to it (the art is decoration), and size it with the size attribute or CSS.
Preview and options: https://www.ascii-magic.com/ascii/pyramid
Rules for coding agents: https://www.ascii-magic.com/ascii/use/ai-coding-agentsPause on the frame you like, pick a look, then download it at an exact size.
MIT licensed and open source on GitHub. It imports one small helper file, kit.js. This is the animation itself: what gets drawn in every frame. The look you pick is applied on top by the player, like a filter, so this file stays the same in every look while the snippets above change with it. Edit it to change the animation; see the docs to make your own.
/* pyramid: a square pyramid turning over a soft shadow, lit like sandstone. */
import { Grid, palette, gradient, KEYS } from "../lib/kit.js";
/* tiny 3D kit for this piece: view space has +z away from the viewer. */
const LIGHT = (() => { const v = [-0.72, 0.55, -0.42], l = Math.hypot(v[0], v[1], v[2]); return [v[0] / l, v[1] / l, v[2] / l]; })();
/** Lambert plus a specular glint, 0..1, for a unit view-space normal. */
function lightOf(n, amb = 0.1, spec = 0.55, pw = 18) {
const d = n[0] * LIGHT[0] + n[1] * LIGHT[1] + n[2] * LIGHT[2];
const rz = 2 * d * n[2] - LIGHT[2];
const s = d > 0 && rz < 0 ? Math.pow(-rz, pw) : 0;
return Math.min(1, amb + Math.max(0, d) * (1 - amb) * 0.78 + s * spec * 0.6);
}
/** Filled triangle in screen cells with a depth test; points are [x, y, depth], larger depth is nearer. */
function tri(g, a, b, c, ch, co) {
const area = (b[0] - a[0]) * (c[1] - a[1]) - (b[1] - a[1]) * (c[0] - a[0]);
if (Math.abs(area) < 1e-6) return;
const x0 = Math.max(0, Math.floor(Math.min(a[0], b[0], c[0]))), x1 = Math.min(g.cols - 1, Math.ceil(Math.max(a[0], b[0], c[0])));
const y0 = Math.max(0, Math.floor(Math.min(a[1], b[1], c[1]))), y1 = Math.min(g.rows - 1, Math.ceil(Math.max(a[1], b[1], c[1])));
for (let y = y0; y <= y1; y++) for (let x = x0; x <= x1; x++) {
const px = x + 0.5, py = y + 0.5;
const w0 = ((b[0] - px) * (c[1] - py) - (b[1] - py) * (c[0] - px)) / area;
const w1 = ((c[0] - px) * (a[1] - py) - (c[1] - py) * (a[0] - px)) / area;
const w2 = 1 - w0 - w1;
if (w0 < -0.02 || w1 < -0.02 || w2 < -0.02) continue;
g.setZ(x, y, w0 * a[2] + w1 * b[2] + w2 * c[2], typeof ch === "function" ? ch(w0, w1, w2) : ch, co);
}
}
/** A depth-tested line between projected points, nudged toward the viewer by bias. */
function seg(g, a, b, ch, co, bias = 0) {
const n = Math.max(1, Math.ceil(Math.max(Math.abs(b[0] - a[0]), Math.abs(b[1] - a[1])) * 1.5));
for (let i = 0; i <= n; i++) {
const f = i / n;
g.setZ(a[0] + (b[0] - a[0]) * f, a[1] + (b[1] - a[1]) * f, a[2] + (b[2] - a[2]) * f + bias, typeof ch === "function" ? ch(f) : ch, co);
}
}
/** Character for a line drawn in screen direction dx, dy (tall cells). */
function slopeChar(dx, dy) {
const a = Math.atan2(dy * 2, dx), s = Math.abs(Math.sin(a)), c = Math.abs(Math.cos(a));
if (s < 0.38) return "─";
if (c < 0.38) return "│";
return (dx > 0) === (dy > 0) ? "╲" : "╱";
}
const rx = ([x, y, z], a) => { const c = Math.cos(a), s = Math.sin(a); return [x, y * c - z * s, y * s + z * c]; };
const ry = ([x, y, z], a) => { const c = Math.cos(a), s = Math.sin(a); return [x * c + z * s, y, -x * s + z * c]; };
const rz = ([x, y, z], a) => { const c = Math.cos(a), s = Math.sin(a); return [x * c - y * s, x * s + y * c, z]; };
const sub = (a, b) => [a[0] - b[0], a[1] - b[1], a[2] - b[2]];
const cross = (a, b) => [a[1] * b[2] - a[2] * b[1], a[2] * b[0] - a[0] * b[2], a[0] * b[1] - a[1] * b[0]];
const unit = (v) => { const l = Math.hypot(v[0], v[1], v[2]) || 1; return [v[0] / l, v[1] / l, v[2] / l]; };
/** Draw a mesh: V in view space, F as index lists (fans), each face lit flat. Normals face away from the origin when orient is set. */
function mesh(g, V, F, P, paint, edgeCo, orient = true) {
const S = V.map(P);
for (let f = 0; f < F.length; f++) {
const idx = F[f];
let n = unit(cross(sub(V[idx[1]], V[idx[0]]), sub(V[idx[2]], V[idx[0]])));
const c = [0, 0, 0];
for (const i of idx) { c[0] += V[i][0] / idx.length; c[1] += V[i][1] / idx.length; c[2] += V[i][2] / idx.length; }
if (orient && n[0] * c[0] + n[1] * c[1] + n[2] * c[2] < 0) n = [-n[0], -n[1], -n[2]];
const [ch, co] = paint(lightOf(n), f, n);
for (let i = 1; i + 1 < idx.length; i++) tri(g, S[idx[0]], S[idx[i]], S[idx[i + 1]], ch, co);
if (edgeCo) for (let i = 0; i < idx.length; i++) {
const a = S[idx[i]], b = S[idx[(i + 1) % idx.length]];
seg(g, a, b, slopeChar(b[0] - a[0], b[1] - a[1]), edgeCo, 0.012);
}
}
}
const SAND = gradient(["#2a1a0c", "#6b4420", "#b77a35", "#e8b867", "#fff1c9"], 12);
export const meta = {
slug: "pyramid",
name: "Pyramid",
category: "solids",
note: "A square pyramid turning slowly above its shadow, each sandstone face lit flat with bright edges.",
tags: ["3d", "pyramid", "loader", "hero", "terminal"],
cols: 56, rows: 28, fps: 30,
palette: palette([...SAND, "#fff8e6", "#1c140c", "#2a1f14"]), // c edge, d e shadow
};
const RAMP = ":-=+*#%@@@";
const VERTS = [[-1, -0.75, -1], [1, -0.75, -1], [1, -0.75, 1], [-1, -0.75, 1], [0, 1.15, 0]];
const FACES = [[0, 1, 2, 3], [0, 1, 4], [1, 2, 4], [2, 3, 4], [3, 0, 4]];
export default function create() {
const { cols, rows } = meta;
const g = new Grid(cols, rows);
const D = 6, SC = 17;
const P = (v) => { const k = D / (v[2] + D); return [cols / 2 + v[0] * k * SC, rows / 2 - 1 - v[1] * k * SC * 0.5, k]; };
const paint = (l) => [RAMP[Math.min(9, Math.floor((0.12 + l * 0.88) * 10))], KEYS[Math.min(11, Math.floor((0.2 + l * 0.8) * 12))]];
return (t) => {
g.clear();
const tilt = 0.32 + Math.sin(t * 0.5) * 0.08;
// floor shadow: an ellipse under the pyramid
const sy = rows / 2 - 1 + 0.95 * SC * 0.5 + 2.2;
for (let y = Math.floor(sy - 2); y <= sy + 2; y++) for (let x = 0; x < cols; x++) {
const d = Math.hypot((x + 0.5 - cols / 2) / 20, (y + 0.5 - sy) / 2.4);
if (d < 1) g.set(x, y, d < 0.6 ? "▒" : "░", d < 0.6 ? "e" : "d");
}
const V = VERTS.map((v) => rx(ry(v, t * 0.7), tilt));
mesh(g, V, FACES, P, paint, "c");
return g.frame();
};
}
/YOUR OWN
The pieces here are hand-built animations. To turn your own photo, logo or video into animated ASCII, use the ASCII Magic editor.