diff --git a/src/main.rs b/src/main.rs index 1741b35..4548403 100644 --- a/src/main.rs +++ b/src/main.rs @@ -41,12 +41,16 @@ struct Args { chars: String, #[clap(long, value_enum)] char_pattern: Vec, + #[clap(long)] + char_invert: Option, #[clap(long, value_enum)] colors: Vec, #[clap(long, value_enum)] color_pattern: Vec, #[clap(long)] color_shift: Option, + #[clap(long)] + color_invert: Option, } #[derive(ValueEnum, Clone)] @@ -89,15 +93,16 @@ enum PatternEnum { struct PatternConfig<'a> { patterns: &'a Vec, shift: Option, + invert: Option, } impl Args { fn char_config(&self) -> PatternConfig { - PatternConfig::new(&self.char_pattern, Some(true)) + PatternConfig::new(&self.char_pattern, Some(true), self.char_invert) } fn color_config(&self) -> PatternConfig { - PatternConfig::new(&self.color_pattern, self.color_shift) + PatternConfig::new(&self.color_pattern, self.color_shift, self.color_invert) } fn pallet(&self, rand: &mut impl Rng) -> Vec { @@ -153,6 +158,9 @@ impl<'a> PatternConfig<'a> { if self.shift.unwrap_or(rand.gen()) { pattern = Box::new(ShiftFactory::new(pattern)) } + if self.invert.unwrap_or(rand.gen()) { + pattern = Box::new(InvertFactory::new(pattern)) + } pattern } } diff --git a/src/transform/invert.rs b/src/transform/invert.rs new file mode 100644 index 0000000..4f092f0 --- /dev/null +++ b/src/transform/invert.rs @@ -0,0 +1,27 @@ +use crate::pattern::*; +use crate::Vector; + +#[derive(derive_more::Constructor)] +pub struct InvertFactory { + child: Box, +} + +#[derive(derive_more::Constructor)] +pub struct Invert { + child: Box, +} + +impl PatternFactory for InvertFactory { + fn create(&self, config: &Config) -> Box { + let mut copy = config.clone(); + copy.step = 1.0 - config.step; + + Box::new(Invert::new(self.child.create(©))) + } +} + +impl Pattern for Invert { + fn sample(&self, pos: Vector) -> f32 { + 1.0 - self.child.sample(pos) + } +} diff --git a/src/transform/mod.rs b/src/transform/mod.rs index daebe43..fc89bb0 100644 --- a/src/transform/mod.rs +++ b/src/transform/mod.rs @@ -1,3 +1,5 @@ +mod invert; mod shift; -pub use shift::*; \ No newline at end of file +pub use invert::*; +pub use shift::*;