MCPcopy Create free account
hub / github.com/donkeyteethUX/iced_plot / heat_color

Function heat_color

examples/heatmap.rs:84–100  ·  view source on GitHub ↗

An ad-hoc colormap for the heatmap values.

(value: f64)

Source from the content-addressed store, hash-verified

82
83// An ad-hoc colormap for the heatmap values.
84fn heat_color(value: f64) -> Color {
85 let v = value.clamp(0.0, 1.0) as f32;
86 let c0 = (0.10, 0.15, 0.45);
87 let c1 = (0.15, 0.60, 0.75);
88 let c2 = (0.85, 0.85, 0.25);
89 let c3 = (0.90, 0.20, 0.12);
90
91 let (a, b, t) = if v < 0.33 {
92 (c0, c1, v / 0.33)
93 } else if v < 0.66 {
94 (c1, c2, (v - 0.33) / 0.33)
95 } else {
96 (c2, c3, (v - 0.66) / 0.34)
97 };
98
99 Color::from_rgb(lerp(a.0, b.0, t), lerp(a.1, b.1, t), lerp(a.2, b.2, t))
100}
101
102fn lerp(a: f32, b: f32, t: f32) -> f32 {
103 a + (b - a) * t

Callers 1

newFunction · 0.85

Calls 1

lerpFunction · 0.85

Tested by

no test coverage detected