aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Schadt <kingdread@gmx.de>2025-11-28 23:07:48 +0100
committerDaniel Schadt <kingdread@gmx.de>2025-11-28 23:07:48 +0100
commit38b533918afe4c12de1042d0cb8bf690c4ed0b8b (patch)
tree56313bf65290094c0167402a2af018f3f9daf769
parentdb116a806c1b81c36a574eba9a4f3c472ddca11f (diff)
downloadhittekaart-38b533918afe4c12de1042d0cb8bf690c4ed0b8b.tar.gz
hittekaart-38b533918afe4c12de1042d0cb8bf690c4ed0b8b.tar.bz2
hittekaart-38b533918afe4c12de1042d0cb8bf690c4ed0b8b.zip
apply cubic scaling to heat count
-rw-r--r--hittekaart/src/renderer/heatmap.rs7
1 files changed, 7 insertions, 0 deletions
diff --git a/hittekaart/src/renderer/heatmap.rs b/hittekaart/src/renderer/heatmap.rs
index 6400e82..d2c2452 100644
--- a/hittekaart/src/renderer/heatmap.rs
+++ b/hittekaart/src/renderer/heatmap.rs
@@ -140,6 +140,13 @@ fn prepare_lut(max: u8) -> Vec<Rgba<u8>> {
iter::once([0, 0, 0, 0].into())
.chain((1..=max).map(|count| {
let alpha = count as f64 / max as f64;
+ // If we simply use alpha here, we get a linear mapping, and a jump from 1 to 2
+ // repetitions is worth as much as a jump from 9 to 10. By transforming alpha via the
+ // cubic function given below, we give more weight to the "early" repetitions by having
+ // a steeper slope, and less weight to later repetitions.
+ // There is no science behind the power 3, others work as well (if you adjust the
+ // sign). It seemed like a decent trade-off though.
+ let alpha = (alpha - 1.0).powi(3) + 1.0;
let color = gradient.at(1.0 - alpha);
color.to_rgba8().into()
}))