pxl: pixel art as code (Hermes)
Write a compact .px.js file → PNG sprites/scenes, TexturePacker-style sheets+JSON, anim strips+GIF, upscaled grid previews, optional live browser paint-replay.
Not the pixel-art skill (photo → retro converter). This skill authors original pixel art from code.
Paths (locked)
PXL_ROOT="$HOME/.hermes/skills/creative/pxl-pixel-art"
PXL="node $PXL_ROOT/bin/pxl.js"
# requires Node ≥ 22.18 (no npm install needed in this checkout)
Examples live in $PXL_ROOT/examples/. Full API: references/reference.md. Terraria-style lights: references/lighting.md (load only when needed).
When to Use
- SEN / game UI needs sprites, icons, tiles, characters, props, scenes
- User wants editable, diffable, reproducible pixel art (not one-shot image gen)
- Need sprite sheet + JSON, multi-frame GIF, or palette-swap variants
- User wants to watch the agent paint (
servelive viewer)
Don't use for: photo→pixel conversion (pixel-art), photoreal/Ghibli images (generate-image-assets / MiniMax), complex 3D.
Workflow (tight loop)
- Write
art.px.jsin the user project (not skill tree). Start from Template below,templates/circular-badge.px.js, or$PXL_ROOT/examples/. - Silhouette first: readable
mxgrid + mono feature (eye bar, V-fin, skull sockets) before glow/poly soup. Unreadable blob → wipe and redraw grid, don't stack more ops. - Build only targets while iterating:
$PXL build art.px.js --only name1,name2 --out <project>/out - Inspect (cheap first — always):
$PXL ascii art.px.js <name>→ palette keys + x/y rulers.
Thenout/_preview/<name>.png(upscaled, checkerboard=transparent, grid every px, darker every 8).
Do not rely on vision for pixel fixes; ascii is SSOT for geometry. Vision 401 / unavailable → ascii + MEDIA delivery only. - Patch one op → rebuild → re-check. Never full-file rewrite for a 2px fix.
- Final delivery build: full
$PXL build art.px.js --out <project>/outwithout--scaleso default large_previewships. ThenMEDIA:the preview paths (Telegram). - Optional live watch: background
$PXL serve art.px.js --port 4321→ URL to user.
Family / cohesion (multi-sprite sets): when shipping player+enemies+UI as one pack, load gamedev-asset-pipeline (Enable/順序) — lock palette roles, view, outline, native size; approve one seed silhouette; batch with swap/shared ramps; QA at game scale on real bg before re-embed. pxl remains the authoring tool; pipeline owns brief+gates.
Full AI multi-action sets: agent-sprite-forge (option, Enable first) — master still → i2v → package.
Iso / 8-dir / camera-true walk: spritecast (option, Enable first) — 3D-guide→redraw→fit.
Ken art law (2026-11-18): SEN 卡/選圖/PECS = pxl only;SEN HTML 要動(行路/8向/iso)= optional spritecast;私人 iso = SpriteCast 主推. pxl remains default for editable static + side-view STG sheets.
Done when: assets under out/sprites|scenes|anims/, silhouette readable in ascii, sheet/GIF present if requested, MEDIA delivered.
Support files: templates/circular-badge.px.js · references/session-gundam-badges.md · references/sen-chibi-chars.md · references/reference.md · references/lighting.md
Errors include file:line:col + asset/layer/op path + “did you mean…”. One broken asset does not block others.
CLI
$PXL build <art.px.js> [--out DIR] [--only a,b] [--scale N] [--no-preview]
$PXL serve <art.px.js> [--port 4321] [--out DIR | --no-out] [--no-preview]
$PXL ascii <art.px.js> <name>
$PXL list <art.px.js>
Art files: .js or .ts ($PXL_ROOT/types/pxl.d.ts for editor completion). Default --out = <art dir>/out.
Template
pal({ k: "#1b1630", g: "#8ccf63", G: "#4c8a44", t: "#2a5560", w: "#fff6e0", r: "#e2585e", R: "#a63a4c" })
ramps("ktGg", "kRr") // dark -> light; drives shade()/light()
// Symmetric: write left half, mirror, outline.
sprite("slime", { mx: true, outline: "k" }, `
....ggg
..ggGGg
.ggGwGg
gggkwgg
gggkkgg
tgggggg
.tttttt`)
sprite("slime_red", { base: "slime", swap: { g: "r", G: "R" } })
sprite("_eye", "wk\nkk") // "_" = part, not exported
sprite("chest", { w: 16, h: 12, outline: "k" },
rect(0, 3, 16, 9, "R"), rect(0, 0, 16, 4, "r"), stamp("_eye", 7, 4), shade([0, 9, 16, 3]))
scene("meadow", { w: 160, h: 96, bg: "w" },
layer("ground", { y: 64 }, rect(0, 0, 160, 32, "G"), noise(0, 0, 160, 32, "g", 0.1, 3)),
layer("props", stamp("slime", 40, 54), stamp("slime_red", 70, 54, { flip: "x" })),
layer("shadow", { shade: true }, poly([38, 64, 88, 64, 92, 67, 34, 67], "k")))
sheet("chars", ["slime*", "chest"], { pad: 1 })
Essentials
| Topic | Rule |
|---|---|
| Colors | 1-char keys via pal; "#hex" ok; . skip; _ erase. Default pico8 (0-f). use("sweetie16"|"db16"|"endesga32"|"gray8") |
| Item order | grids → ops → (c)=>{…} → layers; then mirror→swap→flip→rot→outline(+1px each side)→crop |
| Shapes | px rect box line hline vline circ ring ellipse poly fill wire text |
| Tone | dither grad noise shade light recolor; layer flags shade:/light: + density |
| Regions | [cx,cy,r] · [x,y,w,h] · polygon · (x,y)=>bool · clip(region, …items) |
| Reuse | stamp tile pattern tilemap scatter; globs/group; rflip rswap seed reseed |
| Anim | anim(name, opts, …) frames as patches; or frames:N + c.phase; stamp anim into scenes |
| Glow | glow("keys", { r, strength, bands, ramp, where }) only as a direct item of sprite/scene/anim body, after what it lights. Never inside layer, clip, or frame(...) |
| Lighting | only if needed → load references/lighting.md (lamp, lighting, solid/wall/unlit) |
| Glow+base | sprite("lit", { base: "raw" }, glow(...)) — keep unlit base separate; don't self-base the same name |
Ascii ? | Off-palette pixels (glow/shade/light blend). Expected after glow; judge silhouette on the non-? structure or on unlit base |
Habits (token + quality)
- Symmetric →
mx+outline. Never hand-mirror or hand-outline. - Variants →
base+swap. Details →_parts+stamp. Families →grouporforloop. - Big areas → primitives /
grad/pattern/tilemap. Never giant hand grids. - Organic texture → 2–3 tiny brush parts +
scatterwithon/clip. - No filler noise on walls/floors/plaster (reads as random dots). Marks need a named cause (planks, brick courses, rain streaks, rust under brackets).
noiseonly for granular materials (gravel/sand/asphalt), sparse. - 2–4 shades per material; mnemonic keys (
g/G). - Iterate with
--only; full build for final sheet/export.
Hermes delivery
- After build, show user previews with
MEDIA:/abs/path/to/out/_preview/<name>.png(Telegram). - Prefer project-local
art.px.js+out/next to the game/HTML, not inside the skill dir. - For SEN games: export 1x PNG sprites; upscale in CSS/
image-rendering: pixelated, don't bake huge scale into source unless asked. - Single-file Pages SPA (hk-explorer 類): tiny sprites →
base64 data:image/png嵌CHAR_PXin HTML(免外置 fetch 斷圖);可另存assets/*.png方便 diff。Rebuild 後必須同步更新 base64,唔好只 copy PNG。 - Single-file Canvas STG (doomsday-save-future 類): PLAN often locks one atlas + inline base64 + no fetch. Flow: project
art.px.js→sheet(...)→out/<sheet>.png+.json→ embed viasingle-file-canvas-gamescripts/reembed-sheet.py(accepts/* ---- 貼圖圖集or/* ---- SPRITE SHEET). Minimal pack = ships A/B/C + boss + bullets + ui_focus/ui_bomb.做哂美化also needs thrust/boom/stars/stage props + JS VFX.美化新的敵人: nose-downgrunt/dive/elite(mx+outline+glow); player ships stay nose-up. Wire by flags not new kinds. Palette cyan/pink/white on black. After art change: rebuild and re-b64 (gitignoreout/OK). - SEN HTML STG quiz (
sanfa-guard類): DOM targets + canvas juice, not full atlas required. Pack: 3 themeenemy_*+boss_full/crack/break+fx_bullet|boom|shield. Embedconst ENEMY_SPR/BOSS_SPR/FX_SPR = {…data:image/png;base64…}inindex.html; wire<img class="ship-spr">+image-rendering:pixelated. Boss frame follows HP (full→crack→break). Ken preference this track: pxl first, skip MiniMax/photoreal unless asked. Canonical:~/workspace/vs code/education/value_education/sanfa-guard/art.px.js· seeeducation-game-dev→references/sen-stg-quiz-sanfa-guard.md.
Chibi character recipe (SEN pick-card + grid actor)
Known-good: ~/workspace/vs code/education/computer/hk-explorer-coding/art.px.js (明仔/樂樂). Detail: references/sen-chibi-chars.md.
- Full-width grid (14–16 cols) when props are asymmetric (backpack one side, side bun). Do not
mxif bag/hair breaks mirror — mx doubles the bag. - Silhouette body only first →
outline: "k"onname_base. - Face AFTER outline via
sprite("name", { base: "name_base" }, px…)— eyes/smile on post-outline coords (asciirulers). Drawing eyes in the outlined grid makes 1px gaps collapse under outline fill. - Eye pair pattern that survives outline:
k w .. w kon one row; smilemmon next. Never put face gaps as space chars in grid strings (space = skip → row shortens/pads wrong). Use explicit.. - Signature feature per char (hat color / hair buns / bag) so cards stay distinct at ~140px CSS upscale.
- Optional
*_card= stamp char + soft ellipse shadow; actor can reuse same PNG. - Wire:
image-rendering: pixelatedon.art img/.actor img; keep CSS bob/win/stuck on the actor wrapper (not the PNG).
Anim pulse pattern (glow-safe)
glow is illegal inside frame(). Put one glow on the shared anim body; animate with ring/light/px patches:
anim("pulse", { outline: "k", fps: 8, w: 40, h: 40 },
circ(20, 20, 19, "n"), ring(20, 20, 18, "p"), stamp("icon", 7, 6),
glow("pPq", { r: 3, strength: 0.4, bands: 2 }), // once, shared
frame(),
frame(ring(20, 20, 17, "P"), light([20, 20, 11], 1, 0.3)),
frame(ring(20, 20, 17, "q"), light([20, 20, 13], 2, 0.5)),
frame(ring(20, 20, 17, "P"), light([20, 20, 11], 1, 0.35)),
)
Circular badge recipe
- Icon sprite:
mx: true, outline: "k"grid, 14–28px tall, one signature feature. - Badge:
w/h: 40,circdisc +ringaccent + optional ticklines +stamp(icon). - Optional
glowon badge body after stamp. sheet("…", [icons…, badges…], { pad: 2 }).- Known-good project:
~/workspace/gundam-pxl-badge/gundam_badges.px.js(Unicorn/Freedom/Crossbone). Seereferences/session-gundam-badges.md.
Common Pitfalls
- Confusing with
pixel-artskill — that converts photos; this authors.px.js. glow()insideframe/layer/clip— hard error: glow goes directly in a sprite or scene…. Move glow to body; pulse via ring/light.- Poly/op soup before silhouette — heads become unreadable blobs. Draw grid/
mxsilhouette first; add glow last. --scale Non delivery rebuild — overwrites_previewsmaller (e.g. 84×84). Final user-facing build: no--scale(default @16x previews).--onlyfinal build — leaves stale siblings inout/. Full build before shipping a set.- Duplicate sprite name / self-
base— definename_basethensprite("name", { base: "name_base" }, …). Never declaresprite("ming",…)twice (grid + base rebuild) — hard error already defined. - Hand-drawing both halves / outlines — use
mx+outlineonly when fully symmetric. mxon backpack / one-side props — mirror clones the bag on both hips. Asymmetric chars → full grid, nomx.- Eyes before outline — 1px eye gap gets outline-filled into a blob (
skwkwks). Body+outline first; facepxon base overlay after. - Space in grid rows for “gaps” — space is skip; row length collapses. Eye/face gaps must be
.and every row same width (verify with a length check before build). stamp-only sprite withoutw,hor grid — error no size. Give{ w, h }or a grid string.- Vision on every pixel fix — ascii first; deliver MEDIA previews for human eye.
- Writing into skill
examples/— art stays in user project; skill tree = engine only. - Filler
noiseon flat walls — ban; structure/weathering only. - Forgetting
--out— set explicit projectout/. - Loading
lighting.mdalways — only when lamps/sky light requested. - Updated PNG but stale HTML base64 — SEN single-file embed must re-b64 after every final build.
- Spaces inside
ramps("…")— ramp strings are palette-key sequences; a space is read as unknown key' 'and hard-fails the build. Writeramps("knNmdCcw")notramps("knNmdCc w").
Verification Checklist
-
$PXL list art.px.jsshows expected sprites/scenes/sheets -
$PXL build art.px.js --only …exits 0 -
out/sprites|scenes/*.pngexist at intended size (file/ read dims) -
out/_preview/*.pngreviewed (orasciiclean) - If
sheet(...):out/<sheet>.png+.jsonpresent - If anim: strip/GIF present; frames aligned
- User-visible delivery via MEDIA paths when on Telegram
One-shot smoke
PXL_ROOT="$HOME/.hermes/skills/creative/pxl-pixel-art"
node "$PXL_ROOT/bin/pxl.js" build "$PXL_ROOT/examples/basics.px.js" --only slime,heart --out /tmp/pxl-smoke
open /tmp/pxl-smoke/_preview/slime.png # or MEDIA: that path