mirror of
https://github.com/lisk77/comet.git
synced 2025-10-23 21:38:50 +00:00
feat: added a from_vec function to every color that it can be constructed with a Vec4 to easily interpolate colors
This commit is contained in:
parent
f891de2909
commit
13fd31f632
13 changed files with 46 additions and 208 deletions
|
|
@ -109,4 +109,8 @@ impl Color for Hsla {
|
|||
fn to_vec(&self) -> Vec4 {
|
||||
Vec4::new(self.hue, self.saturation, self.lightness, self.alpha)
|
||||
}
|
||||
|
||||
fn from_vec(color: Vec4) -> Self {
|
||||
Self::new(color.x(), color.y(), color.z(), color.w())
|
||||
}
|
||||
}
|
||||
|
|
@ -107,4 +107,8 @@ impl Color for Hsva {
|
|||
fn to_vec(&self) -> Vec4 {
|
||||
Vec4::new(self.hue, self.saturation, self.value, self.alpha)
|
||||
}
|
||||
|
||||
fn from_vec(color: Vec4) -> Self {
|
||||
Self::new(color.x(), color.y(), color.z(), color.w())
|
||||
}
|
||||
}
|
||||
|
|
@ -170,4 +170,8 @@ impl Color for Hwba {
|
|||
fn to_vec(&self) -> Vec4 {
|
||||
Vec4::new(self.hue, self.whiteness, self.blackness, self.alpha)
|
||||
}
|
||||
|
||||
fn from_vec(color: Vec4) -> Self {
|
||||
Self::new(color.x(), color.y(), color.z(), color.w())
|
||||
}
|
||||
}
|
||||
|
|
@ -151,4 +151,8 @@ impl Color for Laba {
|
|||
fn to_vec(&self) -> Vec4 {
|
||||
Vec4::new(self.lightness, self.a, self.b, self.alpha)
|
||||
}
|
||||
|
||||
fn from_vec(color: Vec4) -> Self {
|
||||
Self::new(color.x(), color.y(), color.z(), color.w())
|
||||
}
|
||||
}
|
||||
|
|
@ -101,4 +101,8 @@ impl Color for Lcha {
|
|||
fn to_vec(&self) -> Vec4 {
|
||||
Vec4::new(self.lightness, self.chroma, self.hue, self.alpha)
|
||||
}
|
||||
|
||||
fn from_vec(color: Vec4) -> Self {
|
||||
Self::new(color.x(), color.y(), color.z(), color.w())
|
||||
}
|
||||
}
|
||||
|
|
@ -25,4 +25,5 @@ mod oklcha;
|
|||
pub trait Color: Copy {
|
||||
fn to_wgpu(&self) -> wgpu::Color;
|
||||
fn to_vec(&self) -> Vec4;
|
||||
fn from_vec(color: Vec4) -> Self;
|
||||
}
|
||||
|
|
@ -139,4 +139,8 @@ impl Color for LinearRgba {
|
|||
fn to_vec(&self) -> Vec4 {
|
||||
Vec4::new(self.red, self.green, self.blue, self.alpha)
|
||||
}
|
||||
|
||||
fn from_vec(color: Vec4) -> Self {
|
||||
Self::new(color.x(), color.y(), color.z(), color.w())
|
||||
}
|
||||
}
|
||||
|
|
@ -121,4 +121,8 @@ impl Color for Oklaba {
|
|||
fn to_vec(&self) -> Vec4 {
|
||||
Vec4::new(self.lightness, self.a, self.b, self.alpha)
|
||||
}
|
||||
|
||||
fn from_vec(color: Vec4) -> Self {
|
||||
Self::new(color.x(), color.y(), color.z(), color.w())
|
||||
}
|
||||
}
|
||||
|
|
@ -100,4 +100,8 @@ impl Color for Oklcha {
|
|||
fn to_vec(&self) -> Vec4 {
|
||||
Vec4::new(self.lightness, self.chroma, self.hue, self.alpha)
|
||||
}
|
||||
|
||||
fn from_vec(color: Vec4) -> Self {
|
||||
Self::new(color.x(), color.y(), color.z(), color.w())
|
||||
}
|
||||
}
|
||||
|
|
@ -352,6 +352,10 @@ impl Color for sRgba<f32> {
|
|||
fn to_vec(&self) -> Vec4 {
|
||||
Vec4::new(self.red, self.green, self.blue, self.alpha)
|
||||
}
|
||||
|
||||
fn from_vec(color: Vec4) -> Self {
|
||||
Self::new(color.x(), color.y(), color.z(), color.w())
|
||||
}
|
||||
}
|
||||
|
||||
impl Color for sRgba<u8> {
|
||||
|
|
@ -367,4 +371,8 @@ impl Color for sRgba<u8> {
|
|||
self.alpha as f32
|
||||
)
|
||||
}
|
||||
|
||||
fn from_vec(color: Vec4) -> Self {
|
||||
Self::new(color.x() as u8, color.y() as u8, color.z() as u8, color.w() as u8)
|
||||
}
|
||||
}
|
||||
|
|
@ -117,4 +117,8 @@ impl Color for Xyza {
|
|||
fn to_vec(&self) -> Vec4 {
|
||||
Vec4::new(self.x, self.y, self.z, self.alpha)
|
||||
}
|
||||
|
||||
fn from_vec(color: Vec4) -> Self {
|
||||
Self::new(color.x(), color.y(), color.z(), color.w())
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue