Files
mice/tools/lpc_extract/recolor.py
T
Matteo Benedetto e26464d843 Merge origin/new-newnassets: new LPC rat assets and animations
Cherry-picked from new-newnassets (3 commits):
- bdf5a8d Add new start animation asset for game launch
- 5f2d09f Fix rat animations and restore map tiles
- 2e2c5bb feat: add LPC-style rat assets, sprite generation scripts, and grid extraction tools

Conflicts resolved:
- engine/sdl2.py: kept 'if scale:' wrapper (compatible, default scale=True)
- units/rat.py: kept animation frame computation (partial_move * 4)
- 12 PNG files (BMP_BABY/MALE/FEMALE_*): kept new-newnassets versions

Cleanup applied: removed ~480 working artifacts not appropriate for the
production repo:
- 25 PNG in repo root (male_rats*.png, spritesheet*.png)
- 416 tile extracts in tools/lpc_extract/grid/
- scattered debug PNGs (bushes, preview, montages, etc.)
- early iteration scripts (animate_rat v1-v4, restyle v2-v10, etc.)

Kept: 32 new LPC-style sprites in assets/Rat_LPC_Style/, 4 animation
sprite sheets in assets/Rat_Animated/, 64 updated Rat sprites, 22
final-version generator scripts, plus all .py/.md updates.
2026-06-27 17:53:45 +02:00

46 lines
1.6 KiB
Python

import glob
import os
from PIL import Image
# Original colors mapped to LPC approximate equivalents
color_map = {
(0, 128, 0): (92, 154, 42), # Dark Green
(0, 255, 0): (124, 184, 47), # Bright Green
(128, 128, 128): (173, 132, 79), # Grey -> Brown dirt
(192, 192, 192): (248, 188, 118), # Light Grey -> Light dirt/sand
(0, 0, 0): (107, 60, 46), # Black -> Dark brown (for softer LPC look)
(255, 255, 0): (224, 156, 76), # Yellow -> LPC Yellow/Orange
(255, 255, 255): (244, 215, 160), # White -> LPC Light bone/sand
(0, 255, 255): (164, 221, 219), # Cyan
(255, 0, 255): (210, 100, 150), # Magenta -> Pink
(255, 0, 0): (180, 50, 50), # Red
}
def recolor_pixel(px):
# px is (r, g, b) or (r, g, b, a)
rgb = px[:3]
if rgb in color_map:
new_rgb = color_map[rgb]
if len(px) == 4:
return new_rgb + (px[3],)
return new_rgb
# If not exact match, find closest by euclidean distance
closest = min(color_map.keys(), key=lambda c: sum((a-b)**2 for a, b in zip(rgb, c)))
new_rgb = color_map[closest]
if len(px) == 4:
return new_rgb + (px[3],)
return new_rgb
input_files = glob.glob('/home/enne2/dev/mice/assets/Rat/*BMP_1*.png')
out_dir = '/home/enne2/dev/mice/assets/Rat_LPC_Style/'
for f in input_files:
img = Image.open(f).convert('RGBA')
new_data = [recolor_pixel(p) for p in img.getdata()]
img.putdata(new_data)
basename = os.path.basename(f)
img.save(os.path.join(out_dir, basename))
print(f"Recolored {basename}")