I have some Twine/SugarCube code you can use for a health bar here. (Click "Jump to Start" on the UI bar to see other sample code there.)
If you take a look at the bottom of that page you will see that I added some code that does what you describe. It uses the HSL (hue, saturation, and luminience) colorspace to change the hue of the healthbar (see this HSL calculator if you want to use different values).
If you have any questions about it, just ask.
Hope that helps! :-)