aboutsummaryrefslogtreecommitdiff
path: root/src/pattern.rs
diff options
context:
space:
mode:
authormetamuffin <yvchraiqi@protonmail.com>2022-06-05 16:17:11 +0200
committermetamuffin <yvchraiqi@protonmail.com>2022-06-05 16:17:11 +0200
commit963c729bcdc1e5f82890f96bc55f1532f6eaf763 (patch)
tree07656d74aee13d075faba4cc13ca28e13dcb7c4a /src/pattern.rs
parent1b70d7d654bef22661cf3184806175fcb17e1bd6 (diff)
downloadblubcat-963c729bcdc1e5f82890f96bc55f1532f6eaf763.tar
blubcat-963c729bcdc1e5f82890f96bc55f1532f6eaf763.tar.bz2
blubcat-963c729bcdc1e5f82890f96bc55f1532f6eaf763.tar.zst
thing
Diffstat (limited to 'src/pattern.rs')
-rw-r--r--src/pattern.rs40
1 files changed, 40 insertions, 0 deletions
diff --git a/src/pattern.rs b/src/pattern.rs
new file mode 100644
index 0000000..ba9899e
--- /dev/null
+++ b/src/pattern.rs
@@ -0,0 +1,40 @@
+use crate::{color::Color, Sample};
+
+pub struct Rainbow;
+impl Sample for Rainbow {
+ fn sample(&mut self, x: f64, _y: f64) -> Color {
+ static PI: f64 = 3.14;
+ let x = x * PI * 2.0;
+ return Color {
+ r: (x + PI / 3.0 * 0.0).sin() * 0.5 + 0.5,
+ g: (x + PI / 3.0 * 2.0).sin() * 0.5 + 0.5,
+ b: (x + PI / 3.0 * 4.0).sin() * 0.5 + 0.5,
+ };
+ }
+}
+
+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()]
+ }
+}
+
+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 a = self.0[index_int % self.0.len()];
+ let b = self.0[(index_int + 1) % self.0.len()];
+ Color::mix(a, b, index_error)
+ }
+}
+
+pub struct Solid(pub Color);
+impl Sample for Solid {
+ fn sample(&mut self, _x: f64, _y: f64) -> Color {
+ self.0
+ }
+}