diff options
author | metamuffin <yvchraiqi@protonmail.com> | 2022-06-05 20:12:58 +0200 |
---|---|---|
committer | metamuffin <yvchraiqi@protonmail.com> | 2022-06-05 20:12:58 +0200 |
commit | 9bcea20a8e6a5ae4661436632570c502c822293a (patch) | |
tree | c7b4c00bbfa203ebb3a65210cecc37a88b0af9cc /src/pattern.rs | |
parent | a5f64a98782cc15bb3cfbc353e271c612e1ff14a (diff) | |
download | blubcat-9bcea20a8e6a5ae4661436632570c502c822293a.tar blubcat-9bcea20a8e6a5ae4661436632570c502c822293a.tar.bz2 blubcat-9bcea20a8e6a5ae4661436632570c502c822293a.tar.zst |
sadfasdf
Diffstat (limited to 'src/pattern.rs')
-rw-r--r-- | src/pattern.rs | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/src/pattern.rs b/src/pattern.rs index 042d0be..8049c23 100644 --- a/src/pattern.rs +++ b/src/pattern.rs @@ -1,5 +1,6 @@ use crate::{color::Color, Sample}; +#[derive(Clone)] pub struct Rainbow; impl Sample for Rainbow { fn sample(&mut self, x: f64, _y: f64) -> Color { @@ -11,15 +12,23 @@ impl Sample for Rainbow { b: (x + PI / 3.0 * 4.0).sin() * 0.5 + 0.5, }; } + fn clone(&self) -> Box<dyn Sample> { + box Clone::clone(self) + } } +#[derive(Clone)] pub struct Sequence(pub Vec<Color>); impl Sample for Sequence { fn sample(&mut self, x: f64, _y: f64) -> Color { self.0[x.rem_euclid(self.0.len() as f64) as usize] } + fn clone(&self) -> Box<dyn Sample> { + box Clone::clone(self) + } } +#[derive(Clone)] pub struct Gradient(pub Vec<Color>); impl Sample for Gradient { fn sample(&mut self, x: f64, _y: f64) -> Color { @@ -29,11 +38,18 @@ impl Sample for Gradient { let b = self.0[(index_int + 1) % self.0.len()]; Color::mix(a, b, index_error) } + fn clone(&self) -> Box<dyn Sample> { + box Clone::clone(self) + } } +#[derive(Clone)] pub struct Solid(pub Color); impl Sample for Solid { fn sample(&mut self, _x: f64, _y: f64) -> Color { self.0 } + fn clone(&self) -> Box<dyn Sample> { + box Clone::clone(self) + } } |