Pseudo pseudorandom color picker
This commit is contained in:
parent
8df3893baa
commit
218ee49a8b
7 changed files with 75 additions and 15 deletions
10
src/lib.rs
10
src/lib.rs
|
@ -1,5 +1,5 @@
|
|||
use config::Config;
|
||||
use std::path::PathBuf;
|
||||
use std::{hash::{DefaultHasher, Hash, Hasher}, path::PathBuf};
|
||||
|
||||
pub mod config;
|
||||
pub mod log;
|
||||
|
@ -13,3 +13,11 @@ pub fn load_config() -> Config {
|
|||
}
|
||||
Config::new(PathBuf::from("./config.toml"))
|
||||
}
|
||||
|
||||
/// Get random-like color id in range 0..16 by computing string hash
|
||||
pub fn color_id_from_name(name: String) -> i32 {
|
||||
let mut s = DefaultHasher::new();
|
||||
name.hash(&mut s);
|
||||
let hash = s.finish();
|
||||
(hash.count_ones() / 4) as i32
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue