mirror of
https://github.com/lisk77/comet.git
synced 2025-10-23 21:38:50 +00:00
feat: added to_vec
to the Color
trait to allow the colors to be lerped and produce gradients
This commit is contained in:
parent
531609e95b
commit
f891de2909
13 changed files with 63 additions and 4 deletions
|
@ -1,3 +1,4 @@
|
|||
use comet_math::Vec4;
|
||||
use crate::{sRgba, Color, Hsva, Hwba, Laba, Lcha, LinearRgba, Oklaba, Oklcha, Xyza};
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Copy)]
|
||||
|
@ -104,4 +105,8 @@ impl Color for Hsla {
|
|||
fn to_wgpu(&self) -> wgpu::Color {
|
||||
self.to_linear().to_wgpu()
|
||||
}
|
||||
|
||||
fn to_vec(&self) -> Vec4 {
|
||||
Vec4::new(self.hue, self.saturation, self.lightness, self.alpha)
|
||||
}
|
||||
}
|
|
@ -1,3 +1,4 @@
|
|||
use comet_math::Vec4;
|
||||
use crate::{sRgba, Color, Hsla, Hwba, Laba, Lcha, LinearRgba, Oklaba, Oklcha, Xyza};
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Copy)]
|
||||
|
@ -102,4 +103,8 @@ impl Color for Hsva {
|
|||
fn to_wgpu(&self) -> wgpu::Color {
|
||||
self.to_linear().to_wgpu()
|
||||
}
|
||||
|
||||
fn to_vec(&self) -> Vec4 {
|
||||
Vec4::new(self.hue, self.saturation, self.value, self.alpha)
|
||||
}
|
||||
}
|
|
@ -1,3 +1,4 @@
|
|||
use comet_math::Vec4;
|
||||
use crate::{sRgba, Color, Hsla, Hsva, Laba, Lcha, LinearRgba, Oklaba, Oklcha, Xyza};
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Copy)]
|
||||
|
@ -165,4 +166,8 @@ impl Color for Hwba {
|
|||
fn to_wgpu(&self) -> wgpu::Color {
|
||||
self.to_linear().to_wgpu()
|
||||
}
|
||||
|
||||
fn to_vec(&self) -> Vec4 {
|
||||
Vec4::new(self.hue, self.whiteness, self.blackness, self.alpha)
|
||||
}
|
||||
}
|
|
@ -1,3 +1,4 @@
|
|||
use comet_math::Vec4;
|
||||
use crate::{sRgba, Color, Hsla, Hsva, Hwba, Lcha, LinearRgba, Oklaba, Oklcha, Xyza};
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Copy)]
|
||||
|
@ -146,4 +147,8 @@ impl Color for Laba {
|
|||
fn to_wgpu(&self) -> wgpu::Color {
|
||||
self.to_linear().to_wgpu()
|
||||
}
|
||||
|
||||
fn to_vec(&self) -> Vec4 {
|
||||
Vec4::new(self.lightness, self.a, self.b, self.alpha)
|
||||
}
|
||||
}
|
|
@ -1,3 +1,4 @@
|
|||
use comet_math::Vec4;
|
||||
use crate::{sRgba, Color, Hsla, Hsva, Hwba, Laba, LinearRgba, Oklaba, Oklcha, Xyza};
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Copy)]
|
||||
|
@ -96,4 +97,8 @@ impl Color for Lcha {
|
|||
fn to_wgpu(&self) -> wgpu::Color {
|
||||
self.to_linear().to_wgpu()
|
||||
}
|
||||
|
||||
fn to_vec(&self) -> Vec4 {
|
||||
Vec4::new(self.lightness, self.chroma, self.hue, self.alpha)
|
||||
}
|
||||
}
|
|
@ -1,4 +1,5 @@
|
|||
pub use comet_math as math;
|
||||
use comet_math::Vec4;
|
||||
pub use linear_rgba::*;
|
||||
pub use rgba::*;
|
||||
pub use hwba::*;
|
||||
|
@ -23,4 +24,5 @@ mod oklcha;
|
|||
|
||||
pub trait Color: Copy {
|
||||
fn to_wgpu(&self) -> wgpu::Color;
|
||||
fn to_vec(&self) -> Vec4;
|
||||
}
|
|
@ -1,4 +1,5 @@
|
|||
use wgpu;
|
||||
use comet_math::Vec4;
|
||||
use crate::{sRgba, Color, Hsla, Hsva, Hwba, Laba, Lcha, Oklaba, Oklcha, Xyza};
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Copy)]
|
||||
|
@ -134,4 +135,8 @@ impl Color for LinearRgba {
|
|||
a: self.alpha as f64
|
||||
}
|
||||
}
|
||||
|
||||
fn to_vec(&self) -> Vec4 {
|
||||
Vec4::new(self.red, self.green, self.blue, self.alpha)
|
||||
}
|
||||
}
|
|
@ -1,3 +1,4 @@
|
|||
use comet_math::Vec4;
|
||||
use crate::{sRgba, Color, Hsla, Hsva, Hwba, Laba, Lcha, LinearRgba, Oklcha, Xyza};
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Copy)]
|
||||
|
@ -116,4 +117,8 @@ impl Color for Oklaba {
|
|||
fn to_wgpu(&self) -> wgpu::Color {
|
||||
self.to_linear().to_wgpu()
|
||||
}
|
||||
|
||||
fn to_vec(&self) -> Vec4 {
|
||||
Vec4::new(self.lightness, self.a, self.b, self.alpha)
|
||||
}
|
||||
}
|
|
@ -1,3 +1,4 @@
|
|||
use comet_math::Vec4;
|
||||
use crate::{sRgba, Color, Hsla, Hsva, Hwba, Laba, Lcha, LinearRgba, Oklaba, Xyza};
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Copy)]
|
||||
|
@ -95,4 +96,8 @@ impl Color for Oklcha {
|
|||
fn to_wgpu(&self) -> wgpu::Color {
|
||||
self.to_linear().to_wgpu()
|
||||
}
|
||||
|
||||
fn to_vec(&self) -> Vec4 {
|
||||
Vec4::new(self.lightness, self.chroma, self.hue, self.alpha)
|
||||
}
|
||||
}
|
|
@ -348,10 +348,23 @@ impl Color for sRgba<f32> {
|
|||
fn to_wgpu(&self) -> wgpu::Color {
|
||||
self.to_linear().to_wgpu()
|
||||
}
|
||||
|
||||
fn to_vec(&self) -> Vec4 {
|
||||
Vec4::new(self.red, self.green, self.blue, self.alpha)
|
||||
}
|
||||
}
|
||||
|
||||
impl Color for sRgba<u8> {
|
||||
fn to_wgpu(&self) -> wgpu::Color {
|
||||
self.to_linear().to_wgpu()
|
||||
}
|
||||
|
||||
fn to_vec(&self) -> Vec4 {
|
||||
Vec4::new(
|
||||
self.red as f32,
|
||||
self.green as f32,
|
||||
self.blue as f32,
|
||||
self.alpha as f32
|
||||
)
|
||||
}
|
||||
}
|
|
@ -1,3 +1,4 @@
|
|||
use comet_math::Vec4;
|
||||
use crate::{sRgba, Color, Hsla, Hsva, Hwba, Laba, Lcha, LinearRgba, Oklaba, Oklcha};
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Copy)]
|
||||
|
@ -112,4 +113,8 @@ impl Color for Xyza {
|
|||
fn to_wgpu(&self) -> wgpu::Color {
|
||||
self.to_linear().to_wgpu()
|
||||
}
|
||||
|
||||
fn to_vec(&self) -> Vec4 {
|
||||
Vec4::new(self.x, self.y, self.z, self.alpha)
|
||||
}
|
||||
}
|
|
@ -1,5 +1,4 @@
|
|||
use std::ops::{Add, Sub, Mul, Div};
|
||||
use crate::{cross, dot, Point3};
|
||||
use std::ops::*;
|
||||
use crate::vector::{Vec2, Vec3, Vec4};
|
||||
|
||||
trait LinearTransformation {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use rand::{Rng, SeedableRng};
|
||||
use comet_log::debug;
|
||||
use crate::utilities::{lerp, lerp2, PI};
|
||||
use crate::{dot, InnerSpace, Vec2};
|
||||
use crate::{InnerSpace, Vec2};
|
||||
|
||||
// TODO
|
||||
// Make noise struct keep their generated noise
|
||||
|
@ -94,7 +94,7 @@ impl PerlinNoise {
|
|||
let nx = x as f64 / self.size.0 as f64;
|
||||
let ny = y as f64 / self.size.1 as f64;
|
||||
let value = self.perlin(nx * self.frequency, ny * self.frequency);
|
||||
noise.push(((value+1.0) * 0.5));
|
||||
noise.push((value+1.0) * 0.5);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue