mirror of
https://github.com/ricoriedel/wipe.git
synced 2024-11-22 16:06:38 +00:00
Add slice transformation
This commit is contained in:
parent
852d3e5bf5
commit
3318db9a26
11
src/main.rs
11
src/main.rs
@ -45,6 +45,8 @@ struct Args {
|
|||||||
char_invert: Option<bool>,
|
char_invert: Option<bool>,
|
||||||
#[clap(long)]
|
#[clap(long)]
|
||||||
char_swap: Option<bool>,
|
char_swap: Option<bool>,
|
||||||
|
#[clap(long)]
|
||||||
|
char_slices: Option<u8>,
|
||||||
#[clap(long, value_enum)]
|
#[clap(long, value_enum)]
|
||||||
colors: Vec<PalletEnum>,
|
colors: Vec<PalletEnum>,
|
||||||
#[clap(long, value_enum)]
|
#[clap(long, value_enum)]
|
||||||
@ -55,6 +57,8 @@ struct Args {
|
|||||||
color_invert: Option<bool>,
|
color_invert: Option<bool>,
|
||||||
#[clap(long)]
|
#[clap(long)]
|
||||||
color_swap: Option<bool>,
|
color_swap: Option<bool>,
|
||||||
|
#[clap(long)]
|
||||||
|
color_slices: Option<u8>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(ValueEnum, Clone)]
|
#[derive(ValueEnum, Clone)]
|
||||||
@ -99,6 +103,7 @@ struct PatternConfig<'a> {
|
|||||||
shift: Option<bool>,
|
shift: Option<bool>,
|
||||||
invert: Option<bool>,
|
invert: Option<bool>,
|
||||||
swap: Option<bool>,
|
swap: Option<bool>,
|
||||||
|
slices: Option<u8>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Args {
|
impl Args {
|
||||||
@ -108,6 +113,7 @@ impl Args {
|
|||||||
Some(true),
|
Some(true),
|
||||||
self.char_invert,
|
self.char_invert,
|
||||||
self.char_swap,
|
self.char_swap,
|
||||||
|
self.char_slices,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -117,6 +123,7 @@ impl Args {
|
|||||||
self.color_shift,
|
self.color_shift,
|
||||||
self.color_invert,
|
self.color_invert,
|
||||||
self.color_swap,
|
self.color_swap,
|
||||||
|
self.color_slices,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -169,6 +176,7 @@ impl<'a> PatternConfig<'a> {
|
|||||||
|
|
||||||
fn create(&self, rand: &mut impl Rng) -> Box<dyn PatternFactory> {
|
fn create(&self, rand: &mut impl Rng) -> Box<dyn PatternFactory> {
|
||||||
let mut pattern = self.create_base(rand);
|
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()) {
|
if self.shift.unwrap_or(rand.gen()) {
|
||||||
pattern = Box::new(ShiftFactory::new(pattern))
|
pattern = Box::new(ShiftFactory::new(pattern))
|
||||||
@ -179,6 +187,9 @@ impl<'a> PatternConfig<'a> {
|
|||||||
if self.swap.unwrap_or(rand.gen()) {
|
if self.swap.unwrap_or(rand.gen()) {
|
||||||
pattern = Box::new(SwapFactory::new(pattern))
|
pattern = Box::new(SwapFactory::new(pattern))
|
||||||
}
|
}
|
||||||
|
if slices != 1 {
|
||||||
|
pattern = Box::new(SliceFactory::new(pattern, slices));
|
||||||
|
}
|
||||||
pattern
|
pattern
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,9 @@
|
|||||||
mod invert;
|
mod invert;
|
||||||
mod shift;
|
mod shift;
|
||||||
|
mod slice;
|
||||||
mod swap;
|
mod swap;
|
||||||
|
|
||||||
pub use invert::*;
|
pub use invert::*;
|
||||||
pub use shift::*;
|
pub use shift::*;
|
||||||
|
pub use slice::*;
|
||||||
pub use swap::*;
|
pub use swap::*;
|
||||||
|
26
src/transform/slice.rs
Normal file
26
src/transform/slice.rs
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
use crate::pattern::*;
|
||||||
|
use crate::Vector;
|
||||||
|
|
||||||
|
#[derive(derive_more::Constructor)]
|
||||||
|
pub struct SliceFactory {
|
||||||
|
child: Box<dyn PatternFactory>,
|
||||||
|
scale: u8,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(derive_more::Constructor)]
|
||||||
|
pub struct Slice {
|
||||||
|
child: Box<dyn Pattern>,
|
||||||
|
scale: u8,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl PatternFactory for SliceFactory {
|
||||||
|
fn create(&self, config: &Config) -> Box<dyn Pattern> {
|
||||||
|
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
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user