diff options
author | metamuffin <yvchraiqi@protonmail.com> | 2022-06-05 16:32:07 +0200 |
---|---|---|
committer | metamuffin <yvchraiqi@protonmail.com> | 2022-06-05 16:32:07 +0200 |
commit | 280cc84e641872564e35d801fbdc7990e013a0e7 (patch) | |
tree | 5bd73691a61f34d5fab0b7ef1ce37668ccb6c9fd | |
parent | 963c729bcdc1e5f82890f96bc55f1532f6eaf763 (diff) | |
download | blubcat-280cc84e641872564e35d801fbdc7990e013a0e7.tar blubcat-280cc84e641872564e35d801fbdc7990e013a0e7.tar.bz2 blubcat-280cc84e641872564e35d801fbdc7990e013a0e7.tar.zst |
polar and translate
-rw-r--r-- | src/main.rs | 15 | ||||
-rw-r--r-- | src/transform.rs | 10 |
2 files changed, 22 insertions, 3 deletions
diff --git a/src/main.rs b/src/main.rs index a0f7e9f..d210aaf 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,8 +3,8 @@ use anyhow::Result; use blubcat::{ color::Color, - pattern::{Rainbow, Sequence, Solid, Gradient}, - transform::{Matrix, Polar}, + pattern::{Gradient, Rainbow, Sequence, Solid}, + transform::{Matrix, Polar, Translate}, Sample, }; use std::{ @@ -33,6 +33,8 @@ TRANSFORM: -r --rotate <angle> -s --scale <factor> -m --matrix <x> <y> <z> <w> + -t --translate <x> <y> + --polar PRESET: --zebra @@ -117,7 +119,14 @@ fn main() -> Result<()> { inner: pat.pop().unwrap(), matrix: ((arg_num(), arg_num()), (arg_num(), arg_num())), }), - "-p" | "--polar" => push_queue.push(box Polar(pat.pop().unwrap())), + "--polar" => push_queue.push(box Polar(pat.pop().unwrap())), + "-t" | "--translate" => { + let (x, y) = (arg_num(), arg_num()); + push_queue.push(box Translate { + offset: (x, y), + inner: pat.pop().unwrap(), + }) + } _ => panic!("unknown option {}", &a), } pat.extend(push_queue.drain(..)) diff --git a/src/transform.rs b/src/transform.rs index 8b555d1..3994f1d 100644 --- a/src/transform.rs +++ b/src/transform.rs @@ -22,3 +22,13 @@ impl Sample for Polar { self.0.sample(ang, dist) } } + +pub struct Translate { + pub inner: Box<dyn Sample>, + pub offset: (f64, f64), +} +impl Sample for Translate { + fn sample(&mut self, x: f64, y: f64) -> Color { + self.inner.sample(x + self.offset.0, y + self.offset.1) + } +} |