# sprite_gen Procedural creature sprites for businesses. You give it a business name and logo. It picks a type, builds a creature from parts and recolors it with the logo's brand colors. There are two part libraries: | Library | Size | Art | Registry | |---|---|---|---| | `pixellab` (default) | 64x64 | Generated with [PixelLab](https://pixellab.ai), see [PixelLab library](#pixellab-library) | `sprite_parts_pl.py` + `pixellab_library/*.json` | | `classic` | 96x96 | Hand-written text grids | `sprite_parts.py` | ## Setup ```bash pip install -r requirements.txt ``` You only need an [OpenRouter](https://openrouter.ai) API key if you want the type picked automatically. Skip the key by passing `--type`. ## Generate a sprite ```bash # Type picked from the business name OPENROUTER_API_KEY= python generate_sprite.py "Rosas Landscaping" logos/rosas.png # Add a description to help pick the type OPENROUTER_API_KEY= python generate_sprite.py "Rosas Landscaping" logos/rosas.png --desc "Lawn care and garden design" # Set the type yourself (no API key needed) python generate_sprite.py "Rosas Landscaping" logos/rosas.png --type grass # Set the colors yourself instead of using a logo (main color first) python generate_sprite.py "Rosas Landscaping" --type grass --colors "#2E7D32,#FBC02D" # A different creature for the same business python generate_sprite.py "Rosas Landscaping" logos/rosas.png --type grass --reroll 1 # Both libraries side by side python generate_sprite.py "Rosas Landscaping" logos/rosas.png --type grass --compare ``` Each run writes `sprites/.png`, `sprites/@4x.png` and `sprites/.json` (library, type, parts, colors). With `--reroll N`, the file names end in `-rN`. With `--compare`, each library writes `-.*` and `-compare.png` shows them next to each other at the same height. Both use the same type and colors. | Option | Meaning | |---|---| | `--type T` | Skip the classifier. One of: normal fire water grass electric ice fighting poison ground flying psychic bug rock ghost dragon | | `--desc TEXT` | Description sent to the classifier (default: the name) | | `--colors "#main,#accent"` | Manual colors; overrides the logo | | `--reroll N` | Alternate creature; the name alone always gives the same sprite | | `--library NAME` | `pixellab` (default) or `classic` | | `--compare` | Render with both libraries and write a comparison sheet | | `--out DIR` | Output folder (default `sprites`) | | `--scale N` | Size of the upscaled copy (default 4, `1` disables it) | Logo colors: transparent pixels, soft edge pixels and a solid white/black/gray background are ignored, and colored brand colors are used before white, black or gray. A logo with only white, black or gray in it still uses those colors. ## Batch Use a CSV with the columns `name,logo,type,description`. Only `name` is required, and rows with no `type` use the classifier. ```bash OPENROUTER_API_KEY= python generate_sprite.py --batch businesses.csv --out sprites ``` Add `--compare` to get both libraries for every row. ## PixelLab library Each base creature has a spec in `pixellab_library/.json`: the prompt and seed for its base image, plus one edit prompt per part ("add a pair of gold horns ..."). `pixellab_library.py` generates the base with PixelLab's pixen model and makes each part as an edit of that exact image. The part is the pixel difference between the edit and the base, so it lines up with the base and gets its attach point automatically. The full spec schema and conventions are in the docstring at the top of `pixellab_library.py`. Art is drawn in a stand-in palette (teal body, crimson details, gold elemental bits) that maps to the recolorable palette keys. Elemental features can use a fixed-color ramp instead (`fire`, `bluefire`, `ice`, `electric`, `ghostfire`): they keep their own colors whatever the brand, and they only appear on their types. When the generator picks parts, it skips any part that would push the sprite past 64x64, so every part can be offered to every body. Needs `PIXELLAB_API_KEY` in the environment or in `.env`. ```bash python pixellab_library.py generate pl_fox --base-only # base image only: review it first python pixellab_library.py generate pl_fox # every missing edit (raw images in pixellab_src/pl_fox/) python pixellab_library.py extract pl_fox # grids in parts_pl_src/, PNGs in parts_pl/, diffs in preview/pixellab/diff/ python pixellab_library.py preview pl_fox # the body with each of its parts python pixellab_library.py preview --cross # every part on every body, one sheet per slot python pixellab_library.py preview --random 60 # real random picks python pixellab_library.py cost # spend so far (pixellab_src/ledger.jsonl) and balance python validate_parts.py --library pixellab --sample 3000 ``` To change a part, edit its spec (new `seed` or wording), then run `generate --parts --force` and `extract `. Regenerating a base deletes that body's old edits. ## Classic library The parts are text grids in `parts_src//.txt`, compiled to `parts//.png`. Weights, compatibility and deny lists live in `sprite_parts.py`. See `AI_PIXEL_ART_GUIDE.md` for the palette and anchor rules. The PixelLab library's grids in `parts_pl_src/` use the same format, plus the fixed-ramp characters listed in `build_parts.py`. ```bash python build_parts.py # compile all grids (or pass part names) python validate_parts.py --library classic --sample 3000 # check colors, anchors, canvas fit on random composites python preview.py --library classic bases # contact sheets in preview/ python preview.py --library classic part back plant_bulb # one part on every base it fits python preview.py --library classic zoom body=base_fox tail=tail_leaf python generate_sprite.py --library classic --sprite-list SPRITES.md # regenerate the part list and weight report ``` Do not run `--make-placeholders --overwrite`, because it replaces the real art with test placeholders.