Skip to content

Commit

Permalink
Merge pull request #20 from Mirabellensaft/voronated_stat_burst
Browse files Browse the repository at this point in the history
Voronated stat burst
  • Loading branch information
Mirabellensaft authored Dec 22, 2023
2 parents 91babde + 49f8ca1 commit 4ca8ec2
Show file tree
Hide file tree
Showing 28 changed files with 928 additions and 585 deletions.
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,38 @@ Hello, World!
- [x] add more organic ways to generate images, such as voronoi diagrams
- [ ] adapt composition things to work with voronoi diagrams
- [ ] experiment with L-systems.
- [ ] add noise generator
- [ ] add camera input, so the generated art can be a reaction to what already is on paper.
- [ ] project layout that allows for easy transitions between creating art work with lots of predefined functions, writing custom parts for the frame work and switching between different works of art.
- [ ] generate art without svg output, by addressing the pen plotter directly
- [ ] input from hardware rngs

## Changes, Thoughts and Learnings (newest first)

### December 21st, 2023

Epiphany!💡 I have been on this track, implementing traits for shared behavior of the types `VoronoiDiagram` and `Grid`. But the actual breakthrough in reducing tons of somewhat similar code is the idea, that the `Grid` is only a special case of a voronoi diagram. One, where all cells have exactly four sides, and corresponding sides have the same length throughout the entire thing. The main difference besides the data type is that in the `Grid` version, the cell sides are constructed first, and the center point follows, the `VoronoiDiagram` type does it the other way around. In the `Grid` type, single fields can be addressed by their row and column number, which is mostly convenient as a picture in my head, but in practice requires the same iteration over and over again.And maybe it's not needed? Maybe each `Grid` cell has enough identifying properties to work without that, just like the `VoronoiDiagram`.

I am not sure if I will implement this fully soon, as I feel I am also due to make more art. But realization definitely feels like a huge lesson towards more generic, reusable and thus cleaner code. The key to avoid writing so much duplicate code in the first place is to think bigger, with more use cases from the start.

Another step I took towards making the library part more generic is moving most of the composition implementation to the project part, and only keep the traits and type definitions in place. This seems way more logic, as the implementations were rather specific for my artistic work, and this is not the purpose of the crate.



### December 12th, 2023

Refactored the way Grid and Voronoi Diagrams are constructed. Now all diagram types are constructed with the same constructor, only with different variants, which in the end decides, which diagram type is first built. I added a trait, so that the diagram types can share behavior regarding compositional aspects.
This way I was able to remove a lot of somewhat similar, somewhat duplicate code, and suddenly I had way less types named Voronoi something.
I slowly get the way, one needs to think code a lot bigger then what you're currently working on. The ability to see future variants of something, future expansions, and functions. Not being able to see that leads to rewriting code a lot.

<figure>
<img
src="https://github.com/Mirabellensaft/sanguine/blob/main/images/image_00012.png"
width="150"
height="300"
alt="Tesselated Voronoi Cells">
<figcaption>Tesselated Voronoi Cells.</figcaption>
</figure>

### December 8th, 2023

Expand Down
Binary file added images/image_00012.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 6 additions & 6 deletions output/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use chrono::Local;
use std::env;

mod work;
use work::{star_burst, voronoi, voronoi_simple};
use work::{star_burst, voronoi, voronoi_simple, voronated_star_burst};

fn main() {
env::set_var("RUST_BACKTRACE", "1");
Expand All @@ -19,23 +19,23 @@ fn main() {
// voronoi::form_group();

if let Some(exclusion) = exclusion::Exclusion::make_exclusion(path, &mut content) {
for i in 0..5 {
for i in 0..10 {
// let parameters = Parameters{ height: 1200, width: 600, margin: 2, rows: 0, columns: 0, layout_type: LayoutType::VoronoiBased(VoronoiType::Uniform(50)) };
let parameters = Parameters {
height: 2400,
width: 1200,
margin: 2,
rows: 20,
columns: 10,
layout_type: LayoutType::GridBased(20, 10),
layout_type: LayoutType::VoronoiBased(VoronoiType::Uniform(50)),
};

match layout::grid::Grid::new(parameters) {
match layout::voronoi::VoronoiDiagram::new(parameters) {
Ok(mut work) => {
let document = Document::new()
.set("viewBox", (0, 0, work.get_width(), work.get_height()))
.add(work.background())
.add(star_burst::form_group(&mut work));
.add(voronated_star_burst::form_group(&mut work));

let local_time = Local::now();
let path = format!("nr_{:03}_{}.svg", i, local_time.format("%Y%m%d_%H%M%S"));
Expand All @@ -45,5 +45,5 @@ fn main() {
}
}
};
println!("None");
println!("None!");
}
1 change: 1 addition & 0 deletions output/src/work/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ pub mod star_burst_lib;
pub mod tester;
pub mod voronoi;
pub mod voronoi_simple;
pub mod voronated_star_burst;
31 changes: 16 additions & 15 deletions output/src/work/star_burst.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,56 +2,57 @@ use rand::{thread_rng, Rng};
use svg::node::element::Group;

use sanguine_lib::resources::{
border_coordinates::AllBorderCoordinates,
border_coordinates::all::AllBorderCoordinates,
composition::{Composition, CompositionCenter, Density},
layout::{grid::Grid, Layout},
};

use super::star_burst_lib;
use super::star_burst_lib::{self, grid_comp::MyGrid};

const RADIUS_MID: std::ops::RangeInclusive<i32> = 3_i32..=6_i32;
const RADIUS_HIGH: std::ops::RangeInclusive<i32> = 5_i32..=10_i32;
const RADIUS_FOCUS: std::ops::RangeInclusive<i32> = 10_i32..=20_i32;

pub fn form_group(work: &mut Grid) -> Group {
pub fn form_group(work: Grid) -> Group {
let mut graph = Group::new();
let mut my_work = MyGrid(work);

// Creates a baseline composition
work.add_center(CompositionCenter::Bottom);
work.add_random_low(30);
work.add_random_center(6);
work.connect_centers();
work.add_random_low(10);
my_work.add_center(CompositionCenter::Bottom);
my_work.add_random_low(30);
my_work.add_random_center(6);
my_work.connect_centers();
my_work.add_random_low(10);

let mut all_coords = AllBorderCoordinates::new(work, 10);
let mut all_coords = AllBorderCoordinates::new(&my_work.0, 10);
all_coords.tesselate();
all_coords.slight_chaos();

// Fills the gaps and edges in the baseline composition
work.retro_composition();
my_work.retro_composition();

// Drawing of the Elements
for row in 0..work.get_rows() {
for col in 0..work.get_columns() {
for row in 0..my_work.0.get_rows() {
for col in 0..my_work.0.get_columns() {
let mut rng = thread_rng();

let mut radius = 0;

match work.container[row][col].density {
match my_work.0.container[row][col].density {
Density::Mid => radius = rng.gen_range(RADIUS_MID),
Density::High => radius = rng.gen_range(RADIUS_HIGH),
Density::Focus => radius = rng.gen_range(RADIUS_FOCUS),
Density::Edge(_) => radius = rng.gen_range(RADIUS_MID),
Density::ThreeWay(_) => radius = rng.gen_range(RADIUS_MID),
_ => (),
}
let field = &work.get_fields()[row as usize][col as usize];
let field = &my_work.0.get_fields()[row as usize][col as usize];
println!(
"field: x{}, y{}, width{}, height{}",
field.x, field.y, field.column_width, field.row_height
);
graph = star_burst_lib::draw::everything(
work.container[row][col].density,
my_work.0.container[row][col].density.clone(),
&all_coords.0[row][col],
field,
radius,
Expand Down
20 changes: 8 additions & 12 deletions output/src/work/star_burst_lib/draw.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use super::{lines, threeways};
use rand::{thread_rng, Rng};
use sanguine_lib::resources::{
border_coordinates::BorderCoordinates,
border_coordinates::cell_border::CellBorderCoords,
composition::{Density, Direction},
layout::grid::Field,
shapes::{circle::Circle, line::Line, point::Point},
Expand All @@ -10,17 +10,13 @@ use svg::{node::element::Group, Node};

pub fn everything(
density: Density,
border_coordinates: &BorderCoordinates,
border_coordinates: &CellBorderCoords,
field: &Field,
radius: i32,
mut graph: Group,
) -> Group {
let mut rng = thread_rng();

println!(
"draw field: x{}, y{}, w{}, h{}",
field.x, field.y, field.column_width, field.row_height
);
match density {
Density::Empty => (),
Density::Transition(Direction::UpDown) => {
Expand Down Expand Up @@ -63,11 +59,11 @@ pub fn everything(

let first = &border_coordinates.0[side];
let second = &border_coordinates.0[second_side];
lines::diagonal(&mut graph, dir, first, second, 0, 10);
lines::diagonal(&mut graph, &dir, first, second, 0, 10);

let first = &border_coordinates.0[third_side];
let second = &border_coordinates.0[2];
lines::diagonal(&mut graph, dir, first, second, 0, 10);
lines::diagonal(&mut graph, &dir, first, second, 0, 10);
}

Density::Edge(direction) => {
Expand All @@ -93,22 +89,22 @@ pub fn everything(
Direction::LeftDown => {
let second_side = &border_coordinates.0[1];
let first_side = &border_coordinates.0[2];
lines::diagonal(&mut graph, direction, first_side, second_side, 0, 10)
lines::diagonal(&mut graph, &direction, first_side, second_side, 0, 10)
}
Direction::LeftUp => {
let first_side = &border_coordinates.0[1];
let second_side = &border_coordinates.0[0];
lines::diagonal(&mut graph, direction, &first_side, &second_side, 0, 10)
lines::diagonal(&mut graph, &direction, &first_side, &second_side, 0, 10)
}
Direction::RightDown => {
let second_side = &border_coordinates.0[3];
let first_side = &border_coordinates.0[2];
lines::diagonal(&mut graph, direction, &first_side, &second_side, 0, 10)
lines::diagonal(&mut graph, &direction, &first_side, &second_side, 0, 10)
}
Direction::RightUp => {
let first_side = &border_coordinates.0[3];
let second_side = &border_coordinates.0[0];
lines::diagonal(&mut graph, direction, &first_side, &second_side, 0, 10)
lines::diagonal(&mut graph, &direction, &first_side, &second_side, 0, 10)
}
_ => (),
};
Expand Down
Loading

0 comments on commit 4ca8ec2

Please sign in to comment.