From 920da31dfad59767b5c9b76052b9298b5afaedee Mon Sep 17 00:00:00 2001 From: Curtis McEnroe Date: Tue, 29 Aug 2017 14:30:09 -0400 Subject: Map create time in hue --- ascii-town-heatmap.rs | 55 ++++++++++++++------------------------------------- 1 file changed, 15 insertions(+), 40 deletions(-) diff --git a/ascii-town-heatmap.rs b/ascii-town-heatmap.rs index 8243046..fa818cf 100644 --- a/ascii-town-heatmap.rs +++ b/ascii-town-heatmap.rs @@ -36,33 +36,17 @@ const TORUS_SZ: u32 = 512; const TILE_W: u32 = 8; const TILE_H: u32 = 5; +// ~2017-07-30. +const CREATE_ONE: u64 = 1501439553; + fn main() { - // Read the `torus.csv` into a 2D array of `(access, modify)`. - // Also track the values we see in `BTreeSet` (for ordering). - let mut tiles = [[(0, 0); TORUS_SZ as usize]; TORUS_SZ as usize]; - let mut ord_a = BTreeSet::new(); - let mut ord_m = BTreeSet::new(); + let mut tiles = [[0; TORUS_SZ as usize]; TORUS_SZ as usize]; + let mut ord_c = BTreeSet::new(); for result in csv::Reader::from_reader(io::stdin()).deserialize() { - let Tile { - create_time, - modify_time, - access_count: mut a, - modify_count: mut m, - tile_x: x, - tile_y: y, - .. - } = result.unwrap(); - - // Handle old migrated values. - if modify_time == create_time && m > 0 { - a += 1; - m = 0; - } - - ord_a.insert(a); - ord_m.insert(m); - - tiles[y][x] = (a, m); + let Tile { tile_x: x, tile_y: y, mut create_time, .. } = result.unwrap(); + if create_time == 1 { create_time = CREATE_ONE } + ord_c.insert(create_time); + tiles[y][x] = create_time; } // Normalize all values by mapping them to equally spaced values in [0, 1]. @@ -71,28 +55,19 @@ fn main() { (x, i as f64 / (ord.len() - 1) as f64) }).collect() }; - let normal_a = normal_map(ord_a); - let normal_m = normal_map(ord_m); + let normal_c = normal_map(ord_c); // Compose the heatmap image in-memory from the 2D array. let mut heatmap = image::ImageBuffer::new(TORUS_SZ * TILE_W, TORUS_SZ * TILE_H); - let red = hsl::HSL::from_rgb(&[255, 0, 0]).h; - // let green = hsl::HSL::from_rgb(&[0, 255, 0]).h; - // let blue = hsl::HSL::from_rgb(&[0, 0, 255]).h; - let yellow = hsl::HSL::from_rgb(&[255, 255, 0]).h; for y in 0..TORUS_SZ { for x in 0..TORUS_SZ { // Get and normalize the values. - let (a, m) = tiles[y as usize][x as usize]; - let a = normal_a[&a].powf(1.0 / 2.0); - let m = normal_m[&m].powf(1.0 / 3.0); + let c = tiles[y as usize][x as usize]; + let c = normal_c[&c]; - // access => luminosity - let l = ((a + m) * 0.5).min(0.7); - // modify => saturation + hue (grey -> red -> yellow) - let interp = |a, b, x| a * (1.0 - x) + b * x; - let h = interp(red, yellow, m.powf(4.0)); - let s = m; + let h = (1.0 - c) * 240.0; + let s = c * 0.5 + 0.5; + let l = if c > 0.0 { c * 0.5 } else { 0.0 }; let (r, g, b) = hsl::HSL { h, s, l }.to_rgb(); let rgb = image::Rgb([r, g, b]); -- cgit 1.4.1