Skip to content

Commit

Permalink
corrected comp
Browse files Browse the repository at this point in the history
  • Loading branch information
Mirabellensaft committed Dec 27, 2023
1 parent d34f5ba commit 2ecf972
Show file tree
Hide file tree
Showing 10 changed files with 235 additions and 49 deletions.
2 changes: 1 addition & 1 deletion output/src/work/star_burst.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ pub fn form_group(work: Grid) -> Group {
"field: x{}, y{}, width{}, height{}",
field.x, field.y, field.column_width, field.row_height
);
graph = star_burst_lib::draw::everything(
graph = star_burst_lib::draw_grid::everything(
my_work.0.container[row][col].density.clone(),
&all_coords.0[row][col],
field,
Expand Down
File renamed without changes.
104 changes: 104 additions & 0 deletions output/src/work/star_burst_lib/draw_voronoi.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
use super::lines;
use rand::thread_rng;
use sanguine_lib::resources::{
border_coordinates::cell_border::CellBorderCoords,
composition::{Density, Direction},
layout::voronoi::Cell,
shapes::{circle::Circle, line::Line},
};
use svg::{node::element::Group, Node};

pub fn everything(
cell: &Cell,
border_coordinates: &CellBorderCoords,
radius: i32,
mut graph: Group,
) -> Group {
let mut rng = thread_rng();

match &cell.density {
Density::Empty => {
let circle = Circle::new(cell.center, 20.0);
graph.append(circle.draw());
}
Density::Transition(Direction::Lines(lines)) => {
println!("draw transition");
println!("touch line: {:?}", lines);

let mut shorter_line = 1;
// let mut indices = Vec::new();
// for border in 0..cell.border_lines.len() {
// for line in lines {
// if cell.border_lines[border].equal(line.0) {}
// indices.push(border)
// }
// }

if border_coordinates.0[lines[0].1].0.len() < border_coordinates.0[lines[1].1].0.len() {
shorter_line = 0_usize;
}
for point in 0..border_coordinates.0[lines[shorter_line].1].0.len() {
let line = Line::new(
border_coordinates.0[lines[0].1].0[point],
border_coordinates.0[lines[1].1].0[point],
);
graph.append(line.draw());
}
}

Density::Lopsided(Direction::Lines(lines)) => {
let circle = Circle::new(cell.center, radius as f32);
graph.append(circle.draw());

for side in &border_coordinates.0 {
for line in lines {
println!("new line/side");
if side.equal(&line.0) {
println!("draw");
lines::to_circle(&mut graph, &side, &circle, 0, side.0.len());
}
println!("free side");
}
}
}

Density::Low => {
if border_coordinates.0.len() % 2 == 0 {
for border in &border_coordinates.0 {}
};
}

Density::Edge(direction) => {
// let center = Point::random_coordinate(field, radius * 2);

// let side = match direction {
// Direction::Up => 0,
// Direction::Down => 2,
// Direction::Left => 3,
// Direction::Right => 1,
// _ => 5,
// };

// let circle = Circle::new(center, radius as f32);
// graph.append(circle.draw());

// let the_side = &border_coordinates.0[side];
// lines::to_circle(&mut graph, the_side, &circle, 0, 10);
}

Density::ThreeWay(lines) => {}

_ => {
let circle = Circle::new(cell.center, radius as f32);
graph.append(circle.draw());

// for side in 0..cell.border_lines.len() {
// let the_side = &border_coordinates.0[side];
for the_side in &border_coordinates.0 {
lines::to_circle(&mut graph, the_side, &circle, 0, the_side.0.len());
}
}
}

graph
}
3 changes: 2 additions & 1 deletion output/src/work/star_burst_lib/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
pub mod draw;
pub mod draw_grid;
pub mod draw_voronoi;
pub mod grid_comp;
pub mod lines;
pub mod threeways;
Expand Down
53 changes: 39 additions & 14 deletions output/src/work/star_burst_lib/voronoi_comp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use rand::prelude::*;

use sanguine_lib::resources::{
composition::CompositionCenter,
layout::voronoi::VoronoiDiagram,
layout::voronoi::{Cell, VoronoiDiagram},
shapes::{line::Line, point::Point},
};

Expand Down Expand Up @@ -56,22 +56,32 @@ impl Composition for MyVoronoiDiagram {
}

fn retro_composition(&mut self) {
println!("retro");
let clone_d = self.0.clone();
for cell in &mut self.0.cells {
match cell.density {
Density::Empty => {
let neighbors = cell.find_neighbors(&clone_d);
let number = neighbors.len();
let contactless = direction_of_contact(neighbors);
match contactless.len() {
0 => cell.set_density(Density::Low),
1 => cell.set_density(Density::ThreeWay(Lines(contactless))),
2 => cell.set_density(Density::Transition(Lines(contactless))),
3 => cell.set_density(Density::Corner(Lines(contactless))),
4 => cell.set_density(Density::Edge(Lines(contactless))),
5 => cell.set_density(Density::Edge(Lines(contactless))),
6 => cell.density = Density::Empty,
_ => {}
let filled_neighbors = direction_of_contact(cell, neighbors);
println!("number {}, empty: {:?}", number, filled_neighbors.len());
// missing case: both are the same
match (number, filled_neighbors.len()) {
(_, 0) => cell.set_density(Density::Empty),
(_, 1) => cell.set_density(Density::Edge(Lines(filled_neighbors))),
(_, 2) => {
cell.set_density(Density::Transition(Lines(filled_neighbors)));
println!("transition")
}

(_, 3) => cell.set_density(Density::ThreeWay(Lines(filled_neighbors))),

//or corner
(5, 4) | (6, 4..=5) | (7, 4..=6) | (8, 4..=7) | (9, 4..=8) => {
cell.set_density(Density::Lopsided(Lines(filled_neighbors)))
}

_ => cell.set_density(Density::Low),
}
}
_ => {}
Expand All @@ -84,14 +94,29 @@ impl Composition for MyVoronoiDiagram {
}
}

fn direction_of_contact(neighbors: Vec<(Point, Density, Line)>) -> Vec<Line> {
fn direction_of_contact(cell: &Cell, neighbors: Vec<(Point, Density, Line)>) -> Vec<(Line, usize)> {
let mut touch_line = Vec::new();

for neighbor in neighbors {
match neighbor.1 {
Density::Empty => touch_line.push(neighbor.2),
_ => {}
Density::Empty
| Density::Lopsided(_)
| Density::Edge(_)
| Density::Transition(_)
| Density::Corner(_) => {}

_ => touch_line.push((neighbor.2, 0)),
}
}

for border in 0..cell.border_lines.len() {
for mut line in touch_line.iter_mut() {
if cell.border_lines[border].equal(line.0) {
line.1 = border;
}
}
}
// println!("touch line: {:?}", touch_line);
touch_line
}

Expand Down
70 changes: 41 additions & 29 deletions output/src/work/voronated_star_burst.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,82 +3,94 @@ use svg::{node::element::Group, Node};

use sanguine_lib::resources::{
border_coordinates::all::AllBorderCoordinates,
composition::Density,
composition::{Composition, Density},
layout::{voronoi::VoronoiDiagram, Layout},
shapes::circle::Circle,
};

use crate::work::star_burst_lib;

use super::star_burst_lib::lines;
use super::star_burst_lib::voronoi_comp::MyVoronoiDiagram;

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 VoronoiDiagram) -> Group {
pub fn form_group(work: VoronoiDiagram) -> Group {
let mut graph = Group::new();
let mut rng = thread_rng();

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

let mut all_coords = AllBorderCoordinates::new_from_voronoi(work, 6);
all_coords.tesselate_voronoi(&work);
let mut all_coords = AllBorderCoordinates::new_from_voronoi(&my_work.0, 6);
all_coords.tesselate_voronoi(&my_work.0);
// all_coords.slight_chaos();

// Fills the gaps and edges in the baseline composition
// work.retro_composition();
println!("cmp starts");
for cell in 0..work.cells.len() {
if work.cells[cell].center.y > 1800.0 {

println!("cmp starts {} cells", my_work.0.cells.len());
for cell in 0..my_work.0.cells.len() {
if my_work.0.cells[cell].center.y > 1800.0 {
let truth = rng.gen_bool(1.0 / 3.0);
if truth {
work.cells[cell].density = Density::Mid;
my_work.0.cells[cell].density = Density::High;
} else {
work.cells[cell].density = Density::High;
my_work.0.cells[cell].density = Density::Mid;
}
} else {
let truth = rng.gen_bool(1.0 / 8.0);
let truth = rng.gen_bool(1.0 / 2.0);
if truth {
work.cells[cell].density = Density::Empty;
my_work.0.cells[cell].density = Density::Mid;
} else {
work.cells[cell].density = Density::Mid;
my_work.0.cells[cell].density = Density::Empty;
}
}
}
println!("drawing starts");
my_work.retro_composition();
println!("comp starts");
// Drawing of the Elements
// println!("len cells {}", work.cells.len());
for cell in 0..work.cells.len() {
for cell in 0..my_work.0.cells.len() {
// println!("cell center {:?}", work.cells[cell].center);

let mut radius = 0;

match work.cells[cell].density {
match my_work.0.cells[cell].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),
Density::Lopsided(_) => radius = 20,
_ => (),
}
graph = star_burst_lib::draw_voronoi::everything(
&my_work.0.cells[cell],
&all_coords.0[0][cell],
radius,
graph,
);
// match my_work.0.cells[cell].density {
// Density::Mid | Density::High => {
// let circle = Circle::new(my_work.0.cells[cell].center, radius as f32);
// graph.append(circle.draw());

match work.cells[cell].density {
Density::Mid | Density::High => {
let circle = Circle::new(work.cells[cell].center, radius as f32);
graph.append(circle.draw());

for side in &all_coords.0[0][cell].0 {
lines::to_circle(&mut graph, &side, &circle, 0, side.0.len());
}
}
_ => (),
}
// for side in &all_coords.0[0][cell].0 {
// lines::to_circle(&mut graph, &side, &circle, 0, side.0.len());
// }
// }
// _ => (),
// }
}
for cell in work.get_points() {

for cell in my_work.0.get_points() {
for line in &cell.border_lines {
graph.append(line.draw());
}
Expand Down
19 changes: 18 additions & 1 deletion sanguine_lib/src/resources/border_coordinates/one_side.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::resources::shapes::{line::Line, point::Point};
use crate::resources::shapes::{line::Line, point::Point, Shape};
use rand::{thread_rng, Rng};

/// This module contains a bunch of functions that create random coordinates on field borders.
Expand Down Expand Up @@ -61,4 +61,21 @@ impl OneSide {
i = rng.gen_range(0..=1);
}
}

pub fn equal(&self, line: &Line) -> bool {
println!("cell equal line");
for point in &self.0 {
if line.contains(*point) {
println!("true");
true;
} else {
return false;
}
}
false
}

pub fn number_of_points(&self) -> usize {
self.0.len()
}
}
3 changes: 2 additions & 1 deletion sanguine_lib/src/resources/composition/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ pub trait Composition {

#[derive(Clone, Debug, PartialEq)]
pub enum Density {
Lopsided(Direction),
Transition(Direction),
ThreeWay(Direction),
Corner(Direction),
Expand Down Expand Up @@ -58,7 +59,7 @@ pub enum Direction {
Down,
Left,
Right,
Lines(Vec<Line>),
Lines(Vec<(Line, usize)>),
}

/// A possibility to set a center in the entire composition.
Expand Down
9 changes: 8 additions & 1 deletion sanguine_lib/src/resources/layout/voronoi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,17 @@ impl Layout for VoronoiDiagram {
impl Cell {
pub fn find_neighbors(&self, diagram: &VoronoiDiagram) -> Vec<(Point, Density, Line)> {
let mut neighbors_centers = Vec::new();
println!("self center: {:?}", self.center);
for side in &self.border_lines {
for cell in &diagram.get_points() {
for other_side in &cell.border_lines {
if side.equal(*other_side) {
if side.equal(*other_side) && cell.center != self.center {
println!(
"center: {:?}, density: {:?}, side: {:?}",
cell.center,
cell.get_density(),
*side,
);
neighbors_centers.push((cell.center, cell.get_density(), *side));
}
}
Expand Down
Loading

0 comments on commit 2ecf972

Please sign in to comment.