Green to red color sweep

BlitzPlus Forums/BlitzPlus Programming/Green to red color sweep

schilcote(Posted 2011) [#1]
Simple question, I need to make a health display that goes from green to red as your health goes down. How do I turn the raw maxhp and hp variables into RGB values?


Warpy(Posted 2011) [#2]
red = (1-hp/float(maxhp))*255
green = 255*hp/float(maxhp)
Color red,green,0


(the float bit is to make sure the number doesn't get rounded down to 0 as an integer)


schilcote(Posted 2011) [#3]
Ahh, I see how that works. It gets the percent of HP left, then gets that percentage of 255, right?


Warpy(Posted 2011) [#4]
Yep