diff options
Diffstat (limited to 'src/main.rs')
-rw-r--r-- | src/main.rs | 66 |
1 files changed, 32 insertions, 34 deletions
diff --git a/src/main.rs b/src/main.rs index 304e1ed..cf6fbb8 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,5 +1,3 @@ -#![feature(box_syntax)] - use anyhow::Result; use blubcat::{ color::Color, @@ -95,85 +93,85 @@ fn main() -> Result<()> { "--ukraine" => stack.push(flag_helper(&["0057B8", "FFD700"])), /* PATTERNS */ - "-R" | "--rainbow" => stack.push(box Rainbow), - "-S" | "--sequence" => stack.push(box Sequence( + "-R" | "--rainbow" => stack.push(Box::new(Rainbow)), + "-S" | "--sequence" => stack.push(Box::new(Sequence( arg_next() .unwrap() .split(",") .map(|e| Color::parse(e).expect("color invalid")) .collect::<Vec<_>>(), - )), - "-G" | "--gradient" => stack.push(box Gradient( + ))), + "-G" | "--gradient" => stack.push(Box::new(Gradient( arg_next() .unwrap() .split(",") .map(|e| Color::parse(e).expect("color invalid")) .collect::<Vec<_>>(), - )), - "-K" | "--const" => stack.push(box Solid( + ))), + "-K" | "--const" => stack.push(Box::new(Solid( Color::parse(arg_next().expect("color expected").as_str()) .expect("invalid color"), - )), + ))), /* TRANSFORMS */ "-s" | "--scale" => { let fac = arg_num(); - push_queue.push(box Matrix { + push_queue.push(Box::new(Matrix { inner: stack.pop().unwrap(), matrix: ((fac, 0.0), (0.0, fac)), - }) + })) } "-r" | "--rotate" => { let angle = arg_num() * PI * 2.0; - push_queue.push(box Matrix { + push_queue.push(Box::new(Matrix { inner: stack.pop().unwrap(), matrix: ((angle.cos(), -angle.sin()), (angle.sin(), angle.cos())), - }) + })) } - "-m" | "--matrix" => push_queue.push(box Matrix { + "-m" | "--matrix" => push_queue.push(Box::new(Matrix { inner: stack.pop().unwrap(), matrix: ((arg_num(), arg_num()), (arg_num(), arg_num())), - }), - "-p" | "--polar" => push_queue.push(box Polar(stack.pop().unwrap())), + })), + "-p" | "--polar" => push_queue.push(Box::new(Polar(stack.pop().unwrap()))), "-t" | "--translate" => { let (x, y) = (arg_num(), arg_num()); - push_queue.push(box Translate { + push_queue.push(Box::new(Translate { offset: (x, y), inner: stack.pop().unwrap(), - }) + })) } - "-T" | "--transpose" => push_queue.push(box Transpose(stack.pop().unwrap())), + "-T" | "--transpose" => push_queue.push(Box::new(Transpose(stack.pop().unwrap()))), "-d" | "--duplicate" => { let p = stack.pop().unwrap(); push_queue.push(p.clone()); push_queue.push(p.clone()) } - "--add" => push_queue.push(box Composite { + "--add" => push_queue.push(Box::new(Composite { a: stack.pop().unwrap(), b: stack.pop().unwrap(), mode: CompositeOperation::Add, - }), - "--subtract" => push_queue.push(box Composite { + })), + "--subtract" => push_queue.push(Box::new(Composite { a: stack.pop().unwrap(), b: stack.pop().unwrap(), mode: CompositeOperation::Subtract, - }), - "--multiply" => push_queue.push(box Composite { + })), + "--multiply" => push_queue.push(Box::new(Composite { a: stack.pop().unwrap(), b: stack.pop().unwrap(), mode: CompositeOperation::Multiply, - }), - "--mix" => push_queue.push(box Composite { + })), + "--mix" => push_queue.push(Box::new(Composite { a: stack.pop().unwrap(), b: stack.pop().unwrap(), mode: CompositeOperation::Mix(arg_num()), - }), + })), - "--abs" => push_queue.push(box Filter { + "--abs" => push_queue.push(Box::new(Filter { inner: stack.pop().unwrap(), mode: FilterOperation::Abs, - }), + })), _ => panic!("unknown option {}", &a), } @@ -184,7 +182,7 @@ fn main() -> Result<()> { } let mut inputs = args.collect::<Vec<String>>(); - let mut pat = stack.pop().unwrap_or_else(|| box Solid(Color::WHITE)); + let mut pat = stack.pop().unwrap_or_else(|| Box::new(Solid(Color::WHITE))); if let Some(a) = arg_extra { inputs.insert(0, a) @@ -202,15 +200,15 @@ fn main() -> Result<()> { } fn flag_helper(colors: &[&str]) -> Box<dyn Sample> { - box Matrix { + Box::new(Matrix { matrix: ((1.0 / 6.0, 1.0 / 6.0), (0.0, 0.0)), - inner: box Sequence( + inner: Box::new(Sequence( colors .into_iter() .map(|e| Color::parse(e).unwrap()) .collect(), - ), - } + )), + }) } fn colorize(file: impl Read, sampler: &mut Box<dyn Sample>) -> Result<()> { |