Skip to content

Commit

Permalink
:3
Browse files Browse the repository at this point in the history
  • Loading branch information
ewen-lbh committed Nov 17, 2024
1 parent 2488019 commit 3393e00
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 2 deletions.
21 changes: 20 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,26 @@ pub fn run(args: cli::Args) -> Result<()> {
let mut canvas = canvas_from_cli(&args);

if args.cmd_image && !args.cmd_video {
canvas = examples::title();
let bgcol = match rand::thread_rng().gen_range(1..=3) {
1 => Color::White,
2 => Color::Pink,
3 => Color::Cyan,
_ => unreachable!(),
};
canvas.set_background(bgcol);
canvas.add_or_replace_layer(canvas.random_layer("feur"));

for (_, obj) in canvas.layer("feur").objects.iter_mut() {
obj.change_color(match (bgcol, rand::thread_rng().gen_bool(0.5)) {
(Color::White, true) => Color::Pink,
(Color::White, false) => Color::Cyan,
(Color::Pink, true) => Color::White,
(Color::Pink, false) => Color::Cyan,
(Color::Cyan, true) => Color::White,
(Color::Cyan, false) => Color::Pink,
_ => unreachable!(),
});
}

let rendered = canvas.render(true)?;
if args.arg_file.ends_with(".svg") {
Expand Down
18 changes: 17 additions & 1 deletion src/objects.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::collections::HashMap;

use crate::{ColorMapping, Fill, Filter, Point, Region, Transformation};
use crate::{Color, ColorMapping, Fill, Filter, Point, Region, Transformation};
use itertools::Itertools;
use wasm_bindgen::prelude::*;

Expand Down Expand Up @@ -66,6 +66,22 @@ impl ColoredObject {
self.filters.clear();
}

pub fn change_color(&mut self, color: Color) {
match self.fill {
None => (),
Some(Fill::Solid(_)) => self.fill = Some(Fill::Solid(color)),
Some(Fill::Translucent(_, opacity)) => {
self.fill = Some(Fill::Translucent(color, opacity))
}
Some(Fill::Hatched(_, pattern, spacing, angle)) => {
self.fill = Some(Fill::Hatched(color, pattern, spacing, angle))
}
Some(Fill::Dotted(_, radius, spacing)) => {
self.fill = Some(Fill::Dotted(color, radius, spacing))
}
}
}

pub fn render(
&self,
cell_size: usize,
Expand Down
65 changes: 65 additions & 0 deletions transfem/1.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions transfem/gen.fish
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
just && while true; ./shapemaker image transfem/1.svg -c pink:#F5A9B8 -c cyan:#5BCEFA --objects-count 5..30; sleep 0.125; end

0 comments on commit 3393e00

Please sign in to comment.