From 562dc2adf60b8569da579b1bb637cea344a7a596 Mon Sep 17 00:00:00 2001 From: Emilia Date: Tue, 24 Oct 2023 20:32:40 -0400 Subject: [PATCH] Change to make colors more evenly distributed --- Cargo.lock | 2 ++ Cargo.toml | 2 ++ src/components/plates/util.rs | 10 ++++++++-- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 72754a0..afd2087 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -555,9 +555,11 @@ name = "plate-tool" version = "0.1.0" dependencies = [ "csv", + "getrandom", "js-sys", "lazy_static", "log", + "rand", "regex", "serde", "serde_json", diff --git a/Cargo.toml b/Cargo.toml index 16c4325..2adadbf 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -22,6 +22,8 @@ uuid = { version = "1.3", features = ["v4", "fast-rng", "macro-diagnostics", "js serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" csv = "1.2" +getrandom = { version = "0.2", features = ["js"] } +rand = { version = "0.8", features = ["small_rng"] } [dev-dependencies] wasm-bindgen-test = "0.3.0" diff --git a/src/components/plates/util.rs b/src/components/plates/util.rs index c22948e..34abf68 100644 --- a/src/components/plates/util.rs +++ b/src/components/plates/util.rs @@ -2,6 +2,10 @@ // https://iquilezles.org/articles/palettes/ // http://dev.thi.ng/gradients/ +use rand::prelude::*; +use rand::rngs::SmallRng; +use lazy_static::lazy_static; + #[derive(Clone, Copy, PartialEq, Debug)] pub struct ColorPalette { a: [f64; 3], @@ -32,8 +36,9 @@ impl ColorPalette { } pub fn get_uuid(&self, t: uuid::Uuid) -> [f64; 3] { - log::debug!("{}", t.as_u128() as f64 / (u128::MAX) as f64); - self.get(t.as_u128() as f64 / (u128::MAX) as f64) + // self.get(t.as_u128() as f64 / (u128::MAX) as f64) + let mut r = SmallRng::seed_from_u64(t.as_u128() as u64); + self.get(r.gen_range(0.0..1.0f64)) } } @@ -54,4 +59,5 @@ impl Palettes { c: [0.100, 0.500, 0.360], d: [0.000, 0.000, 0.650], }; + }