use super::plattle::Plattle;
use std::marker::PhantomData;
pub trait Color {
fn rgb(&self) -> (u8, u8, u8);
fn alpha(&self) -> f64;
}
pub trait Mixable: Color {
fn mix(&self, alpha: f64) -> CompsitableColor<Self> {
CompsitableColor(self, alpha)
}
}
impl<T: Color + Sized> Mixable for T {}
impl Color for Box<&dyn Color> {
fn rgb(&self) -> (u8, u8, u8) {
self.as_ref().rgb()
}
fn alpha(&self) -> f64 {
self.as_ref().alpha()
}
}
pub trait SimpleColor {
fn rgb(&self) -> (u8, u8, u8);
}
impl<T: SimpleColor> Color for T {
fn rgb(&self) -> (u8, u8, u8) {
SimpleColor::rgb(self)
}
fn alpha(&self) -> f64 {
1.0
}
}
pub struct PlattleColor<P: Plattle>(usize, PhantomData<P>);
impl<P: Plattle> PlattleColor<P> {
pub fn pick(idx: usize) -> PlattleColor<P> {
return PlattleColor(idx % P::COLORS.len(), PhantomData);
}
}
impl<P: Plattle> SimpleColor for PlattleColor<P> {
fn rgb(&self) -> (u8, u8, u8) {
P::COLORS[self.0]
}
}
pub struct CompsitableColor<'a, T: Color + ?Sized>(&'a T, f64);
impl<'a, T: Color> Color for CompsitableColor<'a, T> {
fn rgb(&self) -> (u8, u8, u8) {
(self.0).rgb()
}
fn alpha(&self) -> f64 {
(self.0).alpha() * self.1
}
}
pub struct RGBColor(pub u8, pub u8, pub u8);
impl SimpleColor for RGBColor {
fn rgb(&self) -> (u8, u8, u8) {
(self.0, self.1, self.2)
}
}