diff --git a/src/components/plates/util.rs b/src/components/plates/util.rs index 34abf68..845d1ae 100644 --- a/src/components/plates/util.rs +++ b/src/components/plates/util.rs @@ -40,6 +40,19 @@ impl ColorPalette { let mut r = SmallRng::seed_from_u64(t.as_u128() as u64); self.get(r.gen_range(0.0..1.0f64)) } + + pub fn get_ordered(&self, t: uuid::Uuid, ordered_uuids: &Vec) + -> [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]