1// id to rgb color
2pub fn id_to_color(id: u64) -> [u8; 3] {
3 let mut hash = id;
4
5 hash ^= hash >> 16;
6 hash = hash.wrapping_mul(0x85ebca6b);
7 hash ^= hash >> 13;
8 hash = hash.wrapping_mul(0xb00b1355);
9 hash ^= hash >> 16;
10
11 let hue = (hash % 360) as f32;
12 let saturation = 0.7 + ((hash >> 8) % 30) as f32 / 100.0; // 0.7-1.0 for vibrant colors
13 let value = 0.6 + ((hash >> 16) % 40) as f32 / 100.0; // 0.6-1.0 to avoid dark colors
14
15 hsv_to_rgb(hue, saturation, value)
16}
17
18fn hsv_to_rgb(h: f32, s: f32, v: f32) -> [u8; 3] {
19 let c = v * s;
20 let x = c * (1.0 - ((h / 60.0) % 2.0 - 1.0).abs());
21 let m = v - c;
22
23 let (r_prime, g_prime, b_prime) = if h < 60.0 {
24 (c, x, 0.0)
25 } else if h < 120.0 {
26 (x, c, 0.0)
27 } else if h < 180.0 {
28 (0.0, c, x)
29 } else if h < 240.0 {
30 (0.0, x, c)
31 } else if h < 300.0 {
32 (x, 0.0, c)
33 } else {
34 (c, 0.0, x)
35 };
36
37 [
38 ((r_prime + m) * 255.0) as u8,
39 ((g_prime + m) * 255.0) as u8,
40 ((b_prime + m) * 255.0) as u8,
41 ]
42}