Skip to content

Commit

Permalink
Clarify range mapping
Browse files Browse the repository at this point in the history
  • Loading branch information
walles committed Jul 11, 2023
1 parent 5dc88b3 commit 2b99c4c
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions libloadviz/src/renderer/flame.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::ops::Range;

use crate::cpuload::CpuLoad;

use super::{get_load, interpolate, pixel_to_fraction, Renderer, BG_COLOR_RGB};
Expand Down Expand Up @@ -85,11 +87,14 @@ impl Renderer {
}

// Get a 0-1 noise value for this coordinate, that scrolls up with time
let temperature_0_to_1 = (self.noise.get_noise(
internal_detail * distorted_pixel_x,
internal_detail * distorted_pixel_y - dt_seconds * 2.0,
) + 1.0)
/ 2.0;
let temperature_0_to_1 = map_range(
self.noise.get_noise(
internal_detail * distorted_pixel_x,
internal_detail * distorted_pixel_y - dt_seconds * 2.0,
),
-1.0..1.0,
0.0..1.0,
);

// Make the fire cooler the closer the top of the flame we get
let temperature_0_to_1 =
Expand All @@ -99,6 +104,10 @@ impl Renderer {
}
}

fn map_range(value: f32, from: Range<f32>, to: Range<f32>) -> f32 {
return (value - from.start) * (to.end - to.start) / (from.end - from.start) + to.start;
}

/// Lower values mean lower temperatures
fn get_cooling_factor(y_from_bottom_0_to_1: f32, cpu_load: CpuLoad) -> f32 {
let bottom_cooling_layer_thickness_0_to_1 = 0.2;
Expand Down

0 comments on commit 2b99c4c

Please sign in to comment.