weed-sim / icon_loader.py
tostido's picture
WEED-SIM: evolutionary genetics sandbox with embedded Observer Bus
ae853c1
Raw
History Blame Contribute Delete
1.21 kB
import os
from PIL import Image
from image_colorizer import recolor_plant, tint_seed
ASSETS_FOLDER = os.path.join(os.path.dirname(__file__), "assets_px")
SEED_TEMPLATE = os.path.join(ASSETS_FOLDER, "_seed_template.png")
def _stage_key(growth_stage_name):
return growth_stage_name.lower()
def generate_seed_image(seed_profile, growth_stage_name):
"""Render a specimen sprite for the given stage.
- Seed stage: the shared seed silhouette tinted to the strain's bud color.
- Seedling/Mature: the strain base sprite, shown as-is for starters, or
recolored through the leaf/bud masks for bred/cloned offspring.
"""
stage = _stage_key(growth_stage_name)
if stage == "seed":
template = Image.open(SEED_TEMPLATE).convert("RGBA")
return tint_seed(template, seed_profile.bud_color)
path = os.path.join(ASSETS_FOLDER, f"{seed_profile.base_image_name}_{stage}.png")
if not os.path.exists(path):
raise FileNotFoundError(f"[MISSING SPRITE] {path}")
base_image = Image.open(path).convert("RGBA")
if seed_profile.is_starter:
return base_image
return recolor_plant(base_image, seed_profile.leaf_color, seed_profile.bud_color)