Improved color calculations.

This commit is contained in:
Filipe Rodrigues 2023-06-01 12:33:09 +01:00
parent 50026c9f65
commit d4910fe0d2
5 changed files with 133 additions and 37 deletions

View File

@ -7,6 +7,8 @@
"ftmemsim",
"hemem",
"itertools",
"lerp",
"Lerps",
"linejoin",
"Mgzip",
"minmax",
@ -14,6 +16,7 @@
"pico",
"PICOS",
"plotlib",
"powf"
"powf",
"rrggbb"
]
}

129
Cargo.lock generated
View File

@ -63,6 +63,15 @@ version = "1.0.71"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9c7d0618f0e0b7e8ff11427422b64564d5fb0be1940354bfe2e0529b18a9d9b8"
[[package]]
name = "approx"
version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cab112f0a86d568ea0e627cc1d6be74a1e9cd55214684db5561995f6dad897c6"
dependencies = [
"num-traits",
]
[[package]]
name = "autocfg"
version = "1.1.0"
@ -168,7 +177,7 @@ dependencies = [
"heck",
"proc-macro2",
"quote",
"syn",
"syn 2.0.16",
]
[[package]]
@ -256,9 +265,15 @@ checksum = "311a6d2f1f9d60bff73d2c78a0af97ed27f79672f15c238192a5bbb64db56d00"
dependencies = [
"proc-macro2",
"quote",
"syn",
"syn 2.0.16",
]
[[package]]
name = "fast-srgb8"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dd2e7510819d6fbf51a5545c8f922716ecfb14df168a3242f7d33e0239efe6a1"
[[package]]
name = "flate2"
version = "1.0.26"
@ -320,6 +335,7 @@ dependencies = [
"gnuplot",
"gzp",
"itertools",
"palette",
"serde_json",
"tracing",
]
@ -597,6 +613,71 @@ version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39"
[[package]]
name = "palette"
version = "0.7.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e1641aee47803391405d0a1250e837d2336fdddd18b27f3ddb8c1d80ce8d7f43"
dependencies = [
"approx",
"fast-srgb8",
"palette_derive",
"phf",
]
[[package]]
name = "palette_derive"
version = "0.7.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3c02bfa6b3ba8af5434fa0531bf5701f750d983d4260acd6867faca51cdc4484"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.16",
]
[[package]]
name = "phf"
version = "0.11.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "928c6535de93548188ef63bb7c4036bd415cd8f36ad25af44b9789b2ee72a48c"
dependencies = [
"phf_macros",
"phf_shared",
]
[[package]]
name = "phf_generator"
version = "0.11.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b1181c94580fa345f50f19d738aaa39c0ed30a600d95cb2d3e23f94266f14fbf"
dependencies = [
"phf_shared",
"rand",
]
[[package]]
name = "phf_macros"
version = "0.11.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "92aacdc5f16768709a569e913f7451034034178b05bdc8acda226659a3dccc66"
dependencies = [
"phf_generator",
"phf_shared",
"proc-macro2",
"quote",
"syn 1.0.109",
]
[[package]]
name = "phf_shared"
version = "0.11.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e1fb5f6f826b772a8d4c0394209441e7d37cbbb967ae9c7e0e8134365c9ee676"
dependencies = [
"siphasher",
]
[[package]]
name = "pin-project"
version = "1.1.0"
@ -614,7 +695,7 @@ checksum = "39407670928234ebc5e6e580247dd567ad73a3578460c5990f9503df207e8f07"
dependencies = [
"proc-macro2",
"quote",
"syn",
"syn 2.0.16",
]
[[package]]
@ -647,6 +728,21 @@ dependencies = [
"proc-macro2",
]
[[package]]
name = "rand"
version = "0.8.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404"
dependencies = [
"rand_core",
]
[[package]]
name = "rand_core"
version = "0.6.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c"
[[package]]
name = "regex"
version = "1.8.2"
@ -720,7 +816,7 @@ checksum = "8c805777e3930c8883389c602315a24224bcc738b63905ef87cd1420353ea93e"
dependencies = [
"proc-macro2",
"quote",
"syn",
"syn 2.0.16",
]
[[package]]
@ -743,6 +839,12 @@ dependencies = [
"lazy_static",
]
[[package]]
name = "siphasher"
version = "0.3.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7bd3e3206899af3f8b12af284fafc038cc1dc2b41d1b89dd17297221c5d225de"
[[package]]
name = "smallvec"
version = "1.10.0"
@ -764,6 +866,17 @@ version = "0.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623"
[[package]]
name = "syn"
version = "1.0.109"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237"
dependencies = [
"proc-macro2",
"quote",
"unicode-ident",
]
[[package]]
name = "syn"
version = "2.0.16"
@ -792,7 +905,7 @@ checksum = "f9456a42c5b0d803c8cd86e73dd7cc9edd429499f37a3550d286d5e86720569f"
dependencies = [
"proc-macro2",
"quote",
"syn",
"syn 2.0.16",
]
[[package]]
@ -825,7 +938,7 @@ checksum = "0f57e3ca2a01450b1a921183a9c9cbfda207fd822cef4ccb00a65402cbba7a74"
dependencies = [
"proc-macro2",
"quote",
"syn",
"syn 2.0.16",
]
[[package]]
@ -924,7 +1037,7 @@ dependencies = [
"once_cell",
"proc-macro2",
"quote",
"syn",
"syn 2.0.16",
"wasm-bindgen-shared",
]
@ -946,7 +1059,7 @@ checksum = "e128beba882dd1eb6200e1dc92ae6c5dbaa4311aa7bb211ca035779e5efc39f8"
dependencies = [
"proc-macro2",
"quote",
"syn",
"syn 2.0.16",
"wasm-bindgen-backend",
"wasm-bindgen-shared",
]

View File

@ -19,6 +19,7 @@ serde_json = "1.0.96"
bincode = "2.0.0-rc.3"
gzp = "0.11.3"
gnuplot = "0.0.38"
palette = "0.7.2"
# Workspace members
ftmemsim = { path = "ftmemsim" }

View File

@ -14,5 +14,6 @@ gnuplot = { workspace = true }
average = { workspace = true }
bincode = { workspace = true }
gzp = { workspace = true }
palette = { workspace = true }
ftmemsim = { workspace = true }
ftmemsim-util = { workspace = true }

View File

@ -15,6 +15,7 @@ use {
gnuplot::{AutoOption, AxesCommon, DashType, FillRegionType, PlotOption},
gzp::par::decompress::ParDecompress,
itertools::Itertools,
palette::{LinSrgb, Mix},
std::{
collections::{BTreeMap, HashMap, VecDeque},
path::Path,
@ -195,21 +196,10 @@ fn main() -> Result<(), anyhow::Error> {
let mut fg = gnuplot::Figure::new();
let fg_axes2d = fg.axes2d();
for (data_idx, (input_file, data)) in all_data.iter().enumerate() {
let start_color = (1.0, 0.0, 0.0);
let end_color = (0.0, 1.0, 0.0);
let progress = data_idx as f64 / (all_data.len() as f64 - 1.0);
let color = (
start_color.0 * (1.0 - progress) + end_color.0 * progress,
start_color.1 * (1.0 - progress) + end_color.1 * progress,
start_color.2 * (1.0 - progress) + end_color.2 * progress,
);
let color = format!(
"#{:02x}{:02x}{:02x}",
(color.0 * 255.0) as u8,
(color.1 * 255.0) as u8,
(color.2 * 255.0) as u8,
);
let color = LinSrgb::new(1.0, 0.0, 0.0).mix(LinSrgb::new(0.0, 1.0, 0.0), progress);
let color = format!("#{:x}", color.into_format::<u8>());
fg_axes2d.lines(0..data.len(), data, &[
PlotOption::Caption(&format!("Migration count ({})", input_file.display())),
@ -402,23 +392,11 @@ fn main() -> Result<(), anyhow::Error> {
let prev_time = (prev_time2 - min_time) as f64 / (max_time - min_time) as f64;
let cur_time = (cur_time - min_time) as f64 / (max_time - min_time) as f64;
let start_color = (1.0, 0.0, 0.0);
let end_color = (0.0, 1.0, 0.0);
let progress = (prev_temp + cur_temp) / (2.0 * max_temp);
let progress = progress.powf(temp_exponent);
let color = (
start_color.0 * (1.0 - progress) + end_color.0 * progress,
start_color.1 * (1.0 - progress) + end_color.1 * progress,
start_color.2 * (1.0 - progress) + end_color.2 * progress,
);
let color = format!(
"#{:02x}{:02x}{:02x}",
(color.0 * 255.0) as u8,
(color.1 * 255.0) as u8,
(color.2 * 255.0) as u8,
);
let color = LinSrgb::new(1.0, 0.0, 0.0).mix(LinSrgb::new(0.0, 1.0, 0.0), progress);
let color = format!("#{:x}", color.into_format::<u8>());
fg_axes2d.fill_between([prev_time, cur_time], [page_ptr_idx; 2], [page_ptr_idx + 1; 2], &[
PlotOption::Color(&color),