Add palette function for ordered ids
Given an id and a list of sorted ids, yields a color
This commit is contained in:
parent
88e838e102
commit
6e08f47955
|
@ -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]
|
||||||
|
|
Loading…
Reference in New Issue