调整基于Oklch的色相分界。
This commit is contained in:
parent
9fec4a31e9
commit
67164e35fa
@ -20,7 +20,7 @@ pub struct ColorDescription {
|
||||
const COLOR_CARDS_JSON: &str = include_str!("colorcards.json");
|
||||
pub const COLOR_CARDS: LazyLock<Vec<ColorDescription>> =
|
||||
LazyLock::new(|| serde_json::from_str(COLOR_CARDS_JSON).expect("Failed to parse color cards"));
|
||||
const CHROMA_EPSILON: f32 = 0.0001;
|
||||
const CHROMA_EPSILON: f32 = 0.02;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Display, EnumString, EnumIter)]
|
||||
#[strum(serialize_all = "lowercase")]
|
||||
@ -42,7 +42,7 @@ pub enum Category {
|
||||
impl Category {
|
||||
pub fn from_oklch_components(lightness: f32, chroma: f32, hue: f32) -> Self {
|
||||
if chroma < CHROMA_EPSILON {
|
||||
if lightness < 0.1 {
|
||||
if lightness < 0.15 {
|
||||
Category::Black
|
||||
} else if lightness > 0.9 {
|
||||
Category::White
|
||||
@ -52,15 +52,15 @@ impl Category {
|
||||
} else {
|
||||
let processed_hue = hue % 360.0;
|
||||
match processed_hue {
|
||||
0.0..=30.0 => Category::Red,
|
||||
30.0..=60.0 => Category::Orange,
|
||||
60.0..=90.0 => Category::Yellow,
|
||||
90.0..=150.0 => Category::Green,
|
||||
150.0..=210.0 => Category::Cyan,
|
||||
0.0..=15.0 => Category::Magenta,
|
||||
15.0..=45.0 => Category::Red,
|
||||
45.0..=75.0 => Category::Orange,
|
||||
75.0..=120.0 => Category::Yellow,
|
||||
120.0..=180.0 => Category::Green,
|
||||
180.0..=210.0 => Category::Cyan,
|
||||
210.0..=270.0 => Category::Blue,
|
||||
270.0..=300.0 => Category::Purple,
|
||||
300.0..=330.0 => Category::Magenta,
|
||||
330.0..=360.0 => Category::Red,
|
||||
270.0..=345.0 => Category::Purple,
|
||||
345.0..=360.0 => Category::Magenta,
|
||||
_ => Category::Unknown,
|
||||
}
|
||||
}
|
||||
|
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user