Change to make colors more evenly distributed

This commit is contained in:
Emilia Allison 2023-10-24 20:32:40 -04:00
parent 6b09aad289
commit 562dc2adf6
Signed by: emilia
GPG Key ID: 7A3F8997BFE894E0
3 changed files with 12 additions and 2 deletions

2
Cargo.lock generated
View File

@ -555,9 +555,11 @@ name = "plate-tool"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"csv", "csv",
"getrandom",
"js-sys", "js-sys",
"lazy_static", "lazy_static",
"log", "log",
"rand",
"regex", "regex",
"serde", "serde",
"serde_json", "serde_json",

View File

@ -22,6 +22,8 @@ uuid = { version = "1.3", features = ["v4", "fast-rng", "macro-diagnostics", "js
serde = { version = "1.0", features = ["derive"] } serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0" serde_json = "1.0"
csv = "1.2" csv = "1.2"
getrandom = { version = "0.2", features = ["js"] }
rand = { version = "0.8", features = ["small_rng"] }
[dev-dependencies] [dev-dependencies]
wasm-bindgen-test = "0.3.0" wasm-bindgen-test = "0.3.0"

View File

@ -2,6 +2,10 @@
// https://iquilezles.org/articles/palettes/ // https://iquilezles.org/articles/palettes/
// http://dev.thi.ng/gradients/ // http://dev.thi.ng/gradients/
use rand::prelude::*;
use rand::rngs::SmallRng;
use lazy_static::lazy_static;
#[derive(Clone, Copy, PartialEq, Debug)] #[derive(Clone, Copy, PartialEq, Debug)]
pub struct ColorPalette { pub struct ColorPalette {
a: [f64; 3], a: [f64; 3],
@ -32,8 +36,9 @@ impl ColorPalette {
} }
pub fn get_uuid(&self, t: uuid::Uuid) -> [f64; 3] { 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], c: [0.100, 0.500, 0.360],
d: [0.000, 0.000, 0.650], d: [0.000, 0.000, 0.650],
}; };
} }