修正色调调色的方法。

This commit is contained in:
徐涛 2025-01-06 15:05:49 +08:00
parent 3c8cf08c5d
commit c5af60b3de

View File

@ -343,15 +343,16 @@ pub fn tonal_lighten_series(
let mut color_series = Vec::new(); let mut color_series = Vec::new();
let mut lightness = hct.lightness; let mut lightness = hct.lightness;
for _ in 1..=expand_amount { for _ in 1..=expand_amount {
lightness += (1.0 - lightness) * step; lightness += (100.0 - lightness) * step;
let lightened_color = Cam16Jch::new(lightness, hct.chroma, hct.hue); let lightened_color = Cam16Jch::new(lightness, hct.chroma, hct.hue);
let srgb = Srgb::from_color(lightened_color.into_xyz(Parameters::default_static_wp(40.0))); let srgb = Srgb::from_color(lightened_color.into_xyz(Parameters::default_static_wp(40.0)));
color_series.push(format!("{:x}", srgb.into_format::<u8>())); color_series.push(format!("{:x}", srgb.into_format::<u8>()));
} }
Ok(color_series.into_iter().rev().collect()) Ok(color_series)
} }
#[wasm_bindgen]
pub fn tonal_darken_series( pub fn tonal_darken_series(
color: &str, color: &str,
expand_amount: i16, expand_amount: i16,
@ -368,11 +369,11 @@ pub fn tonal_darken_series(
let mut color_series = Vec::new(); let mut color_series = Vec::new();
let mut lightness = hct.lightness; let mut lightness = hct.lightness;
for _ in 1..=expand_amount { for _ in 1..=expand_amount {
lightness *= step; lightness *= 1.0 - step;
let darkened_color = Cam16Jch::new(lightness, hct.chroma, hct.hue); let darkened_color = Cam16Jch::new(lightness, hct.chroma, hct.hue);
let srgb = Srgb::from_color(darkened_color.into_xyz(Parameters::default_static_wp(40.0))); let srgb = Srgb::from_color(darkened_color.into_xyz(Parameters::default_static_wp(40.0)));
color_series.push(format!("{:x}", srgb.into_format::<u8>())); color_series.push(format!("{:x}", srgb.into_format::<u8>()));
} }
Ok(color_series) Ok(color_series.into_iter().rev().collect())
} }