trees: extend temperature() to purple

This commit is contained in:
Astro 2021-08-26 15:43:00 +02:00
parent 8b20c84638
commit 0364650831
1 changed files with 7 additions and 4 deletions

View File

@ -155,13 +155,16 @@ pub fn get_heatmap(state: State) -> (State, Response<Body>) {
(state, res)
}
// 0.0: green, 0.5: yellow, 1.0: red
/// 0.0: green, 0.4: yellow, 0.8: red, 1.0: purple
fn temperature(mut x: f64) -> (f64, f64, f64) {
x = x.max(0.).min(1.);
if x < 0.5 {
(2.0 * x, 1.0, 0.0)
const MAX: f64 = 0.85;
if x < 0.4 {
(MAX * x / 0.4, MAX, 0.0)
} else if x < 0.8 {
(MAX, MAX - MAX * (x - 0.4) / 0.4, 0.0)
} else {
(1.0, 2.0 - 2.0 * x, 0.0)
(MAX, 0.0, MAX * (x - 0.8) / 0.2)
}
}