aboutsummaryrefslogtreecommitdiff
path: root/src/transform.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/transform.rs')
-rw-r--r--src/transform.rs24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/transform.rs b/src/transform.rs
new file mode 100644
index 0000000..8b555d1
--- /dev/null
+++ b/src/transform.rs
@@ -0,0 +1,24 @@
+use crate::{color::Color, Sample};
+
+pub struct Matrix {
+ pub inner: Box<dyn Sample>,
+ pub matrix: ((f64, f64), (f64, f64)),
+}
+impl Sample for Matrix {
+ fn sample(&mut self, x: f64, y: f64) -> Color {
+ let (x, y) = (
+ x * self.matrix.0 .0 + y * self.matrix.0 .1,
+ x * self.matrix.1 .0 + y * self.matrix.1 .1,
+ );
+ self.inner.sample(x, y)
+ }
+}
+
+pub struct Polar(pub Box<dyn Sample>);
+impl Sample for Polar {
+ fn sample(&mut self, x: f64, y: f64) -> Color {
+ let ang = x.atan2(y);
+ let dist = (x * x + y * y).sqrt();
+ self.0.sample(ang, dist)
+ }
+}