diff --git a/src/main.rs b/src/main.rs index 394bf61..521bbe5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -45,6 +45,8 @@ struct Args { char_invert: Option, #[clap(long)] char_swap: Option, + #[clap(long)] + char_slices: Option, #[clap(long, value_enum)] colors: Vec, #[clap(long, value_enum)] @@ -55,6 +57,8 @@ struct Args { color_invert: Option, #[clap(long)] color_swap: Option, + #[clap(long)] + color_slices: Option, } #[derive(ValueEnum, Clone)] @@ -99,6 +103,7 @@ struct PatternConfig<'a> { shift: Option, invert: Option, swap: Option, + slices: Option, } impl Args { @@ -108,6 +113,7 @@ impl Args { Some(true), self.char_invert, self.char_swap, + self.char_slices, ) } @@ -117,6 +123,7 @@ impl Args { self.color_shift, self.color_invert, self.color_swap, + self.color_slices, ) } @@ -169,6 +176,7 @@ impl<'a> PatternConfig<'a> { fn create(&self, rand: &mut impl Rng) -> Box { let mut pattern = self.create_base(rand); + let slices = self.slices.unwrap_or(rand.gen_range(1..=4)); if self.shift.unwrap_or(rand.gen()) { pattern = Box::new(ShiftFactory::new(pattern)) @@ -179,6 +187,9 @@ impl<'a> PatternConfig<'a> { if self.swap.unwrap_or(rand.gen()) { pattern = Box::new(SwapFactory::new(pattern)) } + if slices != 1 { + pattern = Box::new(SliceFactory::new(pattern, slices)); + } pattern } } diff --git a/src/transform/mod.rs b/src/transform/mod.rs index 22d00b2..925e93a 100644 --- a/src/transform/mod.rs +++ b/src/transform/mod.rs @@ -1,7 +1,9 @@ mod invert; mod shift; +mod slice; mod swap; pub use invert::*; pub use shift::*; +pub use slice::*; pub use swap::*; diff --git a/src/transform/slice.rs b/src/transform/slice.rs new file mode 100644 index 0000000..eadbdfc --- /dev/null +++ b/src/transform/slice.rs @@ -0,0 +1,26 @@ +use crate::pattern::*; +use crate::Vector; + +#[derive(derive_more::Constructor)] +pub struct SliceFactory { + child: Box, + scale: u8, +} + +#[derive(derive_more::Constructor)] +pub struct Slice { + child: Box, + scale: u8, +} + +impl PatternFactory for SliceFactory { + fn create(&self, config: &Config) -> Box { + Box::new(Slice::new(self.child.create(config), self.scale)) + } +} + +impl Pattern for Slice { + fn sample(&self, pos: Vector) -> f32 { + self.child.sample(pos) * self.scale as f32 + } +}