diff options
author | metamuffin <yvchraiqi@protonmail.com> | 2022-06-05 17:19:53 +0200 |
---|---|---|
committer | metamuffin <yvchraiqi@protonmail.com> | 2022-06-05 17:19:53 +0200 |
commit | ed2ff677f1977d2c163322ce9e7a55f0740d1f1a (patch) | |
tree | bad9701c11004f2faa05ce21d31a97cd4d874ef3 /src/pattern.rs | |
parent | 280cc84e641872564e35d801fbdc7990e013a0e7 (diff) | |
download | blubcat-ed2ff677f1977d2c163322ce9e7a55f0740d1f1a.tar blubcat-ed2ff677f1977d2c163322ce9e7a55f0740d1f1a.tar.bz2 blubcat-ed2ff677f1977d2c163322ce9e7a55f0740d1f1a.tar.zst |
thing
Diffstat (limited to 'src/pattern.rs')
-rw-r--r-- | src/pattern.rs | 7 |
1 files changed, 3 insertions, 4 deletions
diff --git a/src/pattern.rs b/src/pattern.rs index ba9899e..042d0be 100644 --- a/src/pattern.rs +++ b/src/pattern.rs @@ -16,16 +16,15 @@ impl Sample for Rainbow { pub struct Sequence(pub Vec<Color>); impl Sample for Sequence { fn sample(&mut self, x: f64, _y: f64) -> Color { - self.0[(x * self.0.len() as f64).floor() as usize % self.0.len()] + self.0[x.rem_euclid(self.0.len() as f64) as usize] } } pub struct Gradient(pub Vec<Color>); impl Sample for Gradient { fn sample(&mut self, x: f64, _y: f64) -> Color { - let index = x * self.0.len() as f64; - let index_int = index.floor() as usize; - let index_error = index % 1.0; + let index_int = x.floor() as usize; + let index_error = x % 1.0; let a = self.0[index_int % self.0.len()]; let b = self.0[(index_int + 1) % self.0.len()]; Color::mix(a, b, index_error) |