Python scripts that use Pillow to build playing-card-style sprite sheets (one PNG per suit) and tinted suit PNGs. Suit names, paths, and RGB values come from suits.json (or environment — see below). By default python sprite.py writes both output/sheets/ and output/suits/. colorize_icons.py exposes colorize_icon and export_colored_icons; suits_loader.load_suits() resolves the suit list.
Made by bryanthaboi for Boya Coya on Steam.
python -m venv venv
./venv/Scripts/activate
pip install -r requirements.txt
python sprite.py
deactivateSheets only (skip output/suits/):
python sprite.py --sheets-onlyColored icons only (same output folder as below; equivalent to python colorize_icons.py):
python sprite.py --icons-onlyOr run the suits export module directly:
python colorize_icons.pypython3 -m venv venv
source venv/bin/activate
pip install --upgrade pip
pip install Pillow
python3 sprite.py
deactivatepython3 sprite.py --sheets-only
python3 sprite.py --icons-only
# or: python3 colorize_icons.pyIf you use requirements.txt on Mac, you can run pip install -r requirements.txt instead of installing Pillow alone.
- Python 3 with Pillow installed (
pip install Pilloworpip install -r requirements.txtif you maintain one). m6x11plus.ttfin the project root — used bysprite.pyfor corner ranks (1–10, J, Q, K).- An
icons/folder with suit glyphs and optional face art (see Asset checklist). suits.jsonin the project root (next tosuits_loader.py) — default suit table unless overridden by env.
suits_loader.load_suits() (used by sprite.py and export_colored_icons()):
- Loads a project
.envfile if present (same folder assuits_loader.py). Only sets variables that are not already defined in the real process environment. - If
CARDSHEET_SUITSis set and non-empty, it is parsed as a JSON array of objects{ "name", "path", "color": [r,g,b] }and used instead of a file. - Otherwise it reads
CARDSHEET_SUITS_JSONif set (path to a JSON file), or defaults tosuits.json.
Copy .env.example to .env to document or set overrides locally (.env is gitignored).
| Command | Typical outputs |
|---|---|
python3 sprite.py (default) |
output/sheets/{suit}_sheet.png — 13-card strip per suit, and output/suits/{suit}_colored.png (plus optional output/suits/{jack,queen,king}_original.png). |
python3 sprite.py --sheets-only |
output/sheets/{suit}_sheet.png only. |
python3 sprite.py --icons-only or python3 colorize_icons.py |
output/suits/* only (colored suit icons and optional face copies). |
Paths are relative to the current working directory when you run the script. output/sheets and output/suits are created if missing (output_paths.py).
Constants control layout and scale:
CARD_WIDTH/CARD_HEIGHT— pixel size of each card cell (default 118×162).PADDING— space around the sheet and between cells.GAP— space between corner rank text and the small corner icon.ICON_SCALE— max side of center pips (fraction of card width; aspect preserved; default ~15%).ICON_SCALE_OTHER— max side of corner suit icons (same idea; default matches center so corners stay readable after aspect-preserving resize).FONT_SCALE— TrueType font size relative to card height.
POS— normalized(x, y)positions on the card (0–1), named spots liketl,c,l1…r5.PIP_MAP— for each rank 1–10, which spots get an icon (standard playing-card pip patterns).
For each pip, the script pastes the suit icon at the mapped position. Bottom-half pips (by vertical sort) use a 180°-rotated icon so orientation matches a real deck.
For every column (rank):
- Top-left: rank label (
1–10,J,Q,K) in the suit color, then the small tinted icon below the text. - Bottom-right: label drawn on a small RGBA layer, rotated 180°, pasted so it reads correctly upside-down; the small icon sits above that label (also rotated).
If icons/jack.png, icons/queen.png, and/or icons/king.png exist, they are loaded, resized to about half the card width (height scaled to preserve aspect ratio), tinted with the suit color, and centered on columns 11–13. Missing files print a warning and that rank shows only corners / no center art.
Implemented in colorize_icons.py: colorize_icon() converts the icon to RGBA, keeps the alpha channel, and fills RGB with the suit color so transparent areas stay transparent. sprite.py imports it.
python sprite.py (default) runs export_colored_icons() then builds each sheet into output/sheets/{name}_sheet.png. --icons-only writes only output/suits/; --sheets-only writes only output/sheets/.
load_suits()— returnslist[tuple[name, path, (r, g, b)]]fromCARDSHEET_SUITS(JSON string) or a JSON file (suits.jsonby default).
This file is the shared module and can still be run as a script.
colorize_icon()— tint helper used bysprite.pyandexport_colored_icons().export_colored_icons()— usesload_suits()whensuitsis omitted; writesoutput/suits/{name}_colored.pngand optionaloutput/suits/{face}_original.png(no tint on face copies).
If an icon path is missing, it prints an error for that suit and continues.
sprite.py— full deck generator: default runs suits export + sheets;--icons-only/--sheets-onlylimit which outputs run. Usesload_suits(),colorize_iconfromcolorize_icons, andoutput_pathsfor folders.colorize_icons.py— tinting and colored-icon export;python colorize_icons.pycallsexport_colored_icons()directly.
| Path | Used by |
|---|---|
suits.json (or path in CARDSHEET_SUITS_JSON) |
Default suit table: name, path, color. |
icons/<suit>.png |
Paths listed in that JSON (or in CARDSHEET_SUITS). |
icons/jack.png, queen.png, king.png |
sprite.py center art; export_colored_icons() optional copy-out. |
m6x11plus.ttf |
sprite.py only (font_path in generate_sprite_sheet). |
To add or change suits, edit suits.json or set CARDSHEET_SUITS / CARDSHEET_SUITS_JSON.