I have a float score, which is 0 to 1
I need translate this score to color,
0 is green
1 is red
0.5 should at the middle of green to red gradient color
and so on
how to write this? I have no idea.
The to bottom direction tells you that your gradient is going from top to bottom. So if the first color is 85%, that means that it goes down to 85% of the height of the container. By inverting the percentage (85% -> 15%), you can achieve the result you want. That did the trick!
The linear-gradient syntax is equivalent to placing colour stops as: white 50%, yellow 75% and red 100% as the stops without percentage or distance values will spread out equally to fill the remaining space.
Gradients can blend or transition similar colors (so, for example, different shades of blue or a light orange to a dark red) or completely different or contrasting colors (like purple and red or blue and yellow).
let gradient colour parameter be t
, 0.0 =< t =< 1.0
colour = RGB(255 * t, 255 * (1 - t), 0)
Multiply the float by 255 to get your green value, and multiply (1-float) by 255 to get your red value. If you need to output a css color code, use rgb(x,y,z).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With