aboutsummaryrefslogtreecommitdiff
path: root/src/transform.rs
blob: 8b555d142ba52847bbc971f19f616f9d960cb60c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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)
    }
}