# trait_normalizer.py # Color synthesis helpers for the bud/leaf HSV genetics model. import colorsys def expressed_rgb_from_alleles(hsv_alleles): """Average an HSV allele range (Hue/Saturation/Value lists) into an RGB tuple.""" h = sum(hsv_alleles["Hue"]) / len(hsv_alleles["Hue"]) / 360.0 s = sum(hsv_alleles["Saturation"]) / len(hsv_alleles["Saturation"]) v = sum(hsv_alleles["Value"]) / len(hsv_alleles["Value"]) r, g, b = colorsys.hsv_to_rgb(h, s, v) return (int(r * 255), int(g * 255), int(b * 255)) def derive_plant_color(bud_rgb, leaf_rgb): """Signature color = HSV blend of bud + leaf, kept vivid (used for seed tint / name color).""" bh = colorsys.rgb_to_hsv(*[c / 255.0 for c in bud_rgb]) lh = colorsys.rgb_to_hsv(*[c / 255.0 for c in leaf_rgb]) h, s, v = ((bh[0] + lh[0]) / 2, (bh[1] + lh[1]) / 2, (bh[2] + lh[2]) / 2) r, g, b = colorsys.hsv_to_rgb(h, s, v) return (int(r * 255), int(g * 255), int(b * 255))