mirror of
https://github.com/ricoriedel/wipe.git
synced 2024-11-22 16:06:38 +00:00
Add invert transformation
This commit is contained in:
parent
74e83cd543
commit
91e80cc7c7
12
src/main.rs
12
src/main.rs
@ -41,12 +41,16 @@ struct Args {
|
|||||||
chars: String,
|
chars: String,
|
||||||
#[clap(long, value_enum)]
|
#[clap(long, value_enum)]
|
||||||
char_pattern: Vec<PatternEnum>,
|
char_pattern: Vec<PatternEnum>,
|
||||||
|
#[clap(long)]
|
||||||
|
char_invert: Option<bool>,
|
||||||
#[clap(long, value_enum)]
|
#[clap(long, value_enum)]
|
||||||
colors: Vec<PalletEnum>,
|
colors: Vec<PalletEnum>,
|
||||||
#[clap(long, value_enum)]
|
#[clap(long, value_enum)]
|
||||||
color_pattern: Vec<PatternEnum>,
|
color_pattern: Vec<PatternEnum>,
|
||||||
#[clap(long)]
|
#[clap(long)]
|
||||||
color_shift: Option<bool>,
|
color_shift: Option<bool>,
|
||||||
|
#[clap(long)]
|
||||||
|
color_invert: Option<bool>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(ValueEnum, Clone)]
|
#[derive(ValueEnum, Clone)]
|
||||||
@ -89,15 +93,16 @@ enum PatternEnum {
|
|||||||
struct PatternConfig<'a> {
|
struct PatternConfig<'a> {
|
||||||
patterns: &'a Vec<PatternEnum>,
|
patterns: &'a Vec<PatternEnum>,
|
||||||
shift: Option<bool>,
|
shift: Option<bool>,
|
||||||
|
invert: Option<bool>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Args {
|
impl Args {
|
||||||
fn char_config(&self) -> PatternConfig {
|
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 {
|
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<Color> {
|
fn pallet(&self, rand: &mut impl Rng) -> Vec<Color> {
|
||||||
@ -153,6 +158,9 @@ impl<'a> PatternConfig<'a> {
|
|||||||
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))
|
||||||
}
|
}
|
||||||
|
if self.invert.unwrap_or(rand.gen()) {
|
||||||
|
pattern = Box::new(InvertFactory::new(pattern))
|
||||||
|
}
|
||||||
pattern
|
pattern
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
27
src/transform/invert.rs
Normal file
27
src/transform/invert.rs
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
use crate::pattern::*;
|
||||||
|
use crate::Vector;
|
||||||
|
|
||||||
|
#[derive(derive_more::Constructor)]
|
||||||
|
pub struct InvertFactory {
|
||||||
|
child: Box<dyn PatternFactory>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(derive_more::Constructor)]
|
||||||
|
pub struct Invert {
|
||||||
|
child: Box<dyn Pattern>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl PatternFactory for InvertFactory {
|
||||||
|
fn create(&self, config: &Config) -> Box<dyn Pattern> {
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
}
|
@ -1,3 +1,5 @@
|
|||||||
|
mod invert;
|
||||||
mod shift;
|
mod shift;
|
||||||
|
|
||||||
|
pub use invert::*;
|
||||||
pub use shift::*;
|
pub use shift::*;
|
Loading…
Reference in New Issue
Block a user