Add palette function for ordered ids

Given an id and a list of sorted ids, yields a color
This commit is contained in:
Emilia Allison 2023-12-29 18:01:00 -05:00
parent 88e838e102
commit 6e08f47955
Signed by: emilia
GPG Key ID: 7A3F8997BFE894E0
1 changed files with 13 additions and 0 deletions

View File

@ -40,6 +40,19 @@ impl ColorPalette {
let mut r = SmallRng::seed_from_u64(t.as_u128() as u64); let mut r = SmallRng::seed_from_u64(t.as_u128() as u64);
self.get(r.gen_range(0.0..1.0f64)) self.get(r.gen_range(0.0..1.0f64))
} }
pub fn get_ordered(&self, t: uuid::Uuid, ordered_uuids: &Vec<uuid::Uuid>)
-> [f64; 3] {
let index = ordered_uuids.iter().position(|&x| x == t).expect("uuid must be in list of uuids");
return self.get(Self::space_evenly(index))
}
fn space_evenly(x: usize) -> f64 {
let e: usize = (x.ilog2() + 1) as usize;
let d: usize = (2usize.pow(e as u32)) as usize;
let n: usize = (2*x + 1) % d;
return (n as f64) / (d as f64);
}
} }
#[non_exhaustive] #[non_exhaustive]