I haven't looked at your code, so I don't know how much of a change it would be, but I'd probably go about it by letting users define reference points (a pair consisting of absolute or percentage HP and color) and then interpolating between them. With that system, your default could have two reference points: (100%, #00FF00) and (0, #FF0000). Something like Anthony's request for discrete bands could be done with several more reference points: (100%, #00FF00), (99.99%, #FFFF00), (33.34%, #FFFF00), (33.33%, #FF8000), (1, #FF8000), (0, #FF0000), (-499.99%, #FF0000), (-500%, #000000). To implement it, I'd multiply out the percentages for the token in question (so everything is absolute), sort, then figure out which range you're in. If you're higher than the highest, use the highest; if you're lower than the lowest, use the lowest; if you're exactly at a reference point, use that; otherwise interpolate between the one above you and the one below you.