Skip to content

Commit

Permalink
Merge pull request #19 from Mirabellensaft/voronated_stat_burst
Browse files Browse the repository at this point in the history
eliminated another layer that was too much
  • Loading branch information
Mirabellensaft authored Dec 13, 2023
2 parents aa700ba + ce9d492 commit 91babde
Show file tree
Hide file tree
Showing 17 changed files with 209 additions and 141 deletions.
45 changes: 28 additions & 17 deletions output/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,37 +1,48 @@
use sanguine_lib::resources::{exclusion, layout::{self, Parameters, LayoutType, VoronoiType}};
use sanguine_lib::resources::{
exclusion,
layout::{self, Layout, LayoutType, Parameters, VoronoiType},
};
use svg::Document;

use std::env;
use chrono::Local;
use std::env;

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

fn main() {
env::set_var("RUST_BACKTRACE", "1");

let path = "exclusion.svg";
let mut content = String::new();


// voronoi::form_group();

if let Some(exclusion) = exclusion::Exclusion::make_exclusion(path, &mut content) {
for i in 0..5 {
// 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) };

let work = layout::Work::new(parameters);


let document = Document::new()
.set("viewBox", (0, 0, work.0.get_width(), work.0.get_height()))
.add(work.background())
.add(star_burst::form_group(&work));

let local_time = Local::now();
let path = format!("nr_{:03}_{}.svg", i, local_time.format("%Y%m%d_%H%M%S"));
svg::save(path, &document).unwrap();
let parameters = Parameters {
height: 2400,
width: 1200,
margin: 2,
rows: 20,
columns: 10,
layout_type: LayoutType::GridBased(20, 10),
};

match layout::grid::Grid::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));

let local_time = Local::now();
let path = format!("nr_{:03}_{}.svg", i, local_time.format("%Y%m%d_%H%M%S"));
svg::save(path, &document).unwrap();
}
Err(err) => panic!("{:?}", err),
}
}
};
println!("None");
Expand Down
1 change: 1 addition & 0 deletions output/src/work/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ pub mod star_burst;
pub mod star_burst_lib;
pub mod tester;
pub mod voronoi;
pub mod voronoi_simple;
34 changes: 18 additions & 16 deletions output/src/work/star_burst.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ use svg::node::element::Group;

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

use super::star_burst_lib;
Expand All @@ -13,43 +13,45 @@ 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: &layout::Work) -> Group {
pub fn form_group(work: &mut Grid) -> Group {
let mut graph = Group::new();

// Creates a baseline composition
let mut grid = work.0.get_grid();
grid.add_center(CompositionCenter::Bottom);
grid.add_random_low(30);
grid.add_random_center(6);
grid.connect_centers();
grid.add_random_low(10);
work.add_center(CompositionCenter::Bottom);
work.add_random_low(30);
work.add_random_center(6);
work.connect_centers();
work.add_random_low(10);

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

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

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

let mut radius = 0;

match grid.container[row][col].density {
match work.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.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);
let field = &work.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(
grid.container[row][col].density,
work.container[row][col].density,
&all_coords.0[row][col],
field,
radius,
Expand Down
8 changes: 6 additions & 2 deletions output/src/work/star_burst_lib/draw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ use rand::{thread_rng, Rng};
use sanguine_lib::resources::{
border_coordinates::BorderCoordinates,
composition::{Density, Direction},
shapes::{circle::Circle, line::Line, point::Point}, layout::grid::Field,
layout::grid::Field,
shapes::{circle::Circle, line::Line, point::Point},
};
use svg::{node::element::Group, Node};

Expand All @@ -16,7 +17,10 @@ pub fn everything(
) -> Group {
let mut rng = thread_rng();

println!("draw field: x{}, y{}, w{}, h{}", field.x, field.y, field.column_width, field.row_height);
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
15 changes: 10 additions & 5 deletions output/src/work/tester.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
use rand::thread_rng;
use rand::Rng;
use sanguine_lib::resources::{border_coordinates::AllBorderCoordinates, exclusion::Exclusion, layout::Work, shapes::{circle::Circle, line::Line, point::Point, Shape}};
use sanguine_lib::resources::{
border_coordinates::AllBorderCoordinates,
exclusion::Exclusion,
layout::{grid::Grid, Layout},
shapes::{circle::Circle, line::Line, point::Point, Shape},
};

use svg::node;
use svg::Node;

pub fn form_group(work: Work, ex: &Exclusion) -> node::element::Group {
pub fn form_group(work: Grid, ex: &Exclusion) -> node::element::Group {
let mut graph = node::element::Group::new();

// let comp = CompositionOverlay::new_flat(work);
Expand All @@ -14,14 +19,14 @@ pub fn form_group(work: Work, ex: &Exclusion) -> node::element::Group {
all_coords.tesselate();
all_coords.slight_chaos();

for row in 0..work.0.get_rows() {
for col in 0..work.0.get_columns() {
for row in 0..work.get_rows() {
for col in 0..work.get_columns() {
let mut rng = thread_rng();

let radius = rng.gen_range(7..=15);

let center = Point::random_coordinate(
&work.0.get_fields()[row as usize][col as usize],
&work.get_fields()[row as usize][col as usize],
radius * 2,
);

Expand Down
36 changes: 20 additions & 16 deletions output/src/work/voronated_star_burst.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use svg::node::element::Group;

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

Expand All @@ -17,40 +17,44 @@ pub fn form_group(work: &layout::Work) -> Group {
let mut graph = Group::new();

// Creates a baseline composition
let mut comp = CompositionOverlay::new_empty(layout);
comp.add_center(CompositionCenter::Bottom, layout);
comp.add_random_low(30, layout);
comp.add_random_center(6, layout);
comp.connect_centers();
comp.add_random_low(10, layout);

let mut all_coords = AllBorderCoordinates::new(layout, 10);
let mut grid = work.0.get_grid();
grid.add_center(CompositionCenter::Bottom);
grid.add_random_low(30);
grid.add_random_center(6);
grid.connect_centers();
grid.add_random_low(10);

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

// Fills the gaps and edges in the baseline composition
comp.retro_composition(layout);
grid.retro_composition();

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

let mut radius = 0;

match comp.0[row][col] {
match grid.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.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(
comp.0[row][col],
grid.container[row][col].density,
&all_coords.0[row][col],
&layout.field_container[row as usize][col as usize],
field,
radius,
graph,
);
Expand Down
13 changes: 9 additions & 4 deletions output/src/work/voronoi.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
use sanguine_lib::resources::layout;
use sanguine_lib::resources::{
composition::{Composition, Density},
layout::{voronoi::VoronoiDiagram, Layout},
};
use svg::{node, Node};

pub fn form_group(work: &layout::Work) -> node::element::Group {
pub fn form_group(work: &mut VoronoiDiagram) -> node::element::Group {
// pub fn form_group() {
let mut graph = node::element::Group::new();

for cell in work.0.get_points() {

work.filled(Density::Mid);

for cell in work.get_points() {
for line in &cell.border_lines {
graph.append(line.draw());
}
Expand Down
17 changes: 17 additions & 0 deletions output/src/work/voronoi_simple.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
use sanguine_lib::resources::{
composition::{Composition, Density},
layout::{voronoi::VoronoiDiagram, Layout},
};
use svg::{node, Node};

pub fn form_group(work: &VoronoiDiagram) -> node::element::Group {
// pub fn form_group() {
let mut graph = node::element::Group::new();

for cell in work.get_points() {
for line in &cell.border_lines {
graph.append(line.draw());
}
}
graph
}
10 changes: 5 additions & 5 deletions sanguine_lib/src/resources/border_coordinates.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::resources::{layout::Work, shapes::point::Point};
use crate::resources::{layout::{Layout, grid::Grid}, shapes::point::Point};
use rand::{thread_rng, Rng};

use super::layout::grid::Field;
Expand Down Expand Up @@ -150,14 +150,14 @@ pub struct AllBorderCoordinates(pub Vec<Vec<BorderCoordinates>>);

impl AllBorderCoordinates {
/// Returns a Vector of edge points for an entire work of art.
pub fn new(work: &Work, amount: usize) -> Self {
pub fn new(work: &Grid, amount: usize) -> Self {
let mut vec = Vec::new();

for row in 0..work.0.get_rows() {
for row in 0..work.get_rows() {
let mut inner = Vec::new();
for col in 0..work.0.get_columns() {
for col in 0..work.get_columns() {
inner.push(BorderCoordinates::new(
work.0.get_fields()[row][col],
work.get_fields()[row][col],
amount,
));
}
Expand Down
Loading

0 comments on commit 91babde

Please sign in to comment.