{bl} > 66 and string.format('%.2x%s',(100-{bl})*255/33,'FF00') or {bl} > 16 and string.format('%s%.2x%s','FF',({bl}-16)*255/50,'00') or 'FF0000'
Apply to the color and of the object. It goes gradually from green to yellow to red. I didn't write this but found it...somewhere. Seems to work well...