Skip to content

Commit

Permalink
Merge pull request #29 from Mirabellensaft/blocks
Browse files Browse the repository at this point in the history
add mushrooms
  • Loading branch information
Mirabellensaft authored Oct 22, 2024
2 parents 0021175 + 0b629ba commit b14bbfb
Show file tree
Hide file tree
Showing 6 changed files with 193 additions and 12 deletions.
23 changes: 13 additions & 10 deletions output/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ use chrono::Local;
use std::env;

mod work;
use work::{star_burst, voronated_star_burst, voronoi, voronoi_circloid, voronoi_simple};
use work::{
blocks, mush, mushroom, star_burst, test_circloid, voronated_star_burst, voronoi,
voronoi_simple,
};

fn main() {
env::set_var("RUST_BACKTRACE", "1");
Expand All @@ -18,24 +21,24 @@ fn main() {

// voronoi::form_group();

if let Some(_exclusion) = exclusion::Exclusion::make_exclusion(path, &mut content) {
for i in 0..10 {
if let Some(exclusion) = exclusion::Exclusion::make_exclusion(path, &mut content) {
for i in 0..1 {
// 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,
height: 1200,
width: 1200,
margin: 2,
rows: 20,
columns: 10,
layout_type: LayoutType::VoronoiBased(VoronoiType::Uniform(200)),
margin: 30,
rows: 9,
columns: 9,
layout_type: LayoutType::GridBased(3, 3),
};

match layout::voronoi::VoronoiDiagram::new(parameters) {
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(voronoi_circloid::form_group(&mut work));
.add(mushroom::form_group(work));

let local_time = Local::now();
let path = format!("nr_{:03}_{}.svg", i, local_time.format("%Y%m%d_%H%M%S"));
Expand Down
2 changes: 2 additions & 0 deletions output/src/work/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
pub mod blocks;
pub mod mush;
pub mod mushroom;
pub mod star_burst;
pub mod star_burst_lib;
pub mod test_circloid;
pub mod tester;
pub mod voronated_star_burst;
pub mod voronoi;
Expand Down
71 changes: 71 additions & 0 deletions output/src/work/mushroom.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
use rand::Rng;
use sanguine_lib::resources::shapes::circle::Circle;
use sanguine_lib::resources::shapes::Shape;
use svg::node::element::Group;
use svg::Node;

use sanguine_lib::resources::{
layout::grid::Grid,
shapes::circloid::Circloid,
shapes::{curve::Curve, line::Line, point::Point},
};

pub fn form_group(work: Grid) -> Group {
let mut graph = Group::new();
let rng = &mut rand::thread_rng();

for row in 0..work.rows {
for col in 0..work.columns {
let amplitude_out = rng.gen_range(5.0..10.0);
let frequency_out = rng.gen_range(1.2..3.0);
let radius_out = rng.gen_range(150.0..180.0);
let center_out = Point::new(
work.container[row][col].center.x + rng.gen_range(-20.0..20.0),
work.container[row][col].center.y + rng.gen_range(-20.0..20.0),
);

let amplitude_in = rng.gen_range(2.0..5.0);
let frequency_in = rng.gen_range(1.2..3.0);
let radius_in = rng.gen_range(40.0..65.0);

let center_in = Point::new(
center_out.x + rng.gen_range(-15.0..15.0),
center_out.y + rng.gen_range(-15.0..15.0),
);

let circloid_in = Circloid::new(center_in, radius_in, amplitude_in, frequency_in);
let circloid_out = Circloid::new(center_out, radius_out, amplitude_out, frequency_out);

for i in 0..1000 {
if i % 9 == 0 {
let line = Line::new(circloid_out.point_collection[i], center_in);
let circle = Circle::new(center_in, circloid_in.base_radius + 20.0);
let cp_inter = circle.intersection(line, 0.2).unwrap();

let cp_start = Point::new(
cp_inter.x + rng.gen_range(-3.0..3.0),
cp_inter.y + rng.gen_range(-3.0..3.0),
);

let line = Line::new(circloid_out.point_collection[i], center_out);
let circle = Circle::new(center_out, circloid_out.base_radius - 20.0);
let cp_inter = circle.intersection(line, 1.0).unwrap();

let cp_end = Point::new(
cp_inter.x + rng.gen_range(-3.0..3.0),
cp_inter.y + rng.gen_range(-3.0..3.0),
);

let curve = Curve::new(
circloid_in.point_collection[i],
cp_start,
cp_end,
circloid_out.point_collection[i],
);
graph.append(curve.draw());
}
}
}
}
graph
}
65 changes: 65 additions & 0 deletions output/src/work/test_circloid.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
use svg::node::element::Group;
use svg::Node;

use sanguine_lib::resources::{layout::grid::Grid, shapes::circloid::Circloid};

pub fn form_group(work: Grid) -> Group {
let mut graph = Group::new();
let mut amplitude = 2.0;
let mut frequency = 2.0;
let mut radius = 20.0;

println!(
"rows: {}, col: {}, width: {}, height: {}",
work.rows, work.columns, work.width, work.height
);

for row in 0..work.rows {
amplitude += 1.0;
radius = 20.0;
for col in 0..work.columns {
let center = work.container[row][col].center;

println!("f: {}, a: {}, r: {}", frequency, amplitude, radius);
println!("row: {}, col: {}", row, col);

let circloid = Circloid::new(center, radius, amplitude, frequency);

graph.append(circloid.draw());
radius += 5.0
}
}

// for row in 0..work.rows {
// for col in 0..work.columns {
// let center = work.container[row][col].center;

// println!("f: {}, a: {}, r: {}", frequency, amplitude, radius);
// println!("row: {}, col: {}", row, col);

// let circloid = Circloid::new(center, radius, amplitude, frequency);

// graph.append(circloid.draw());
// radius += 10.0;
// }
// }

// for row in 0..work.rows {
// amplitude += 1.0;
// frequency = 1.4;
// for col in 0..work.columns {
// frequency += 0.2;

// let center = work.container[row][col].center;
// let radius = 80.0;
// println!("f: {}, a: {}, r: {}", frequency, amplitude, radius);
// println!("row: {}, col: {}", row, col);

// let circloid = Circloid::new(center, radius, amplitude, frequency);

// graph.append(circloid.draw());
// }
// }

graph
}
44 changes: 42 additions & 2 deletions sanguine_lib/src/resources/shapes/circloid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ impl Circloid {
let random_start_angle: f64 = rng.gen_range(0.0..2.0 * PI);
let num_points = 1000;
let mut point_collection: Vec<Point> = vec![];
let mut zero_angle_point = Point::new(0.0, 0.0);

// 2/3 of the shape will be a sine wave
let sine_fraction = 2.0 / 3.0;
let sine_fraction = 4.0 / 6.0;
let sine_wave_points = (num_points as f64 * sine_fraction).round() as usize;

for i in 0..=sine_wave_points {
Expand All @@ -51,9 +52,13 @@ impl Circloid {

// Store the first point and move to it
point_collection.push(Point { x, y });

if find_smallest_angle(angle) {
zero_angle_point = Point { x, y };
}
}

// Arc that covers the remaining 1/3 of the shape
// Arc that covers the 1/3 of the shape
let arc_radius = base_radius;
let arc_start_angle = sine_fraction * 2.0 * PI;
let arc_end_angle = 2.0 * PI;
Expand All @@ -71,8 +76,25 @@ impl Circloid {
// Draw the line for the arc
point_collection.push(Point { x, y });
// data = data.line_to((x, y));
if find_smallest_angle(angle) {
zero_angle_point = Point { x, y };
}
}

// note for later:
// Arc that covers the remaining 1/6 of the shape
// this arc transitions from tangent at last former arc point to tangent of first sinus point
if let Some(sorted_point_collection) = reorder_vec_to_0(zero_angle_point, &point_collection)
{
return Circloid {
center: center,
base_radius: base_radius,
amplitude: amplitude, // 2.0..8.0
frequency: frequency, //1.2..3.0
point_collection: sorted_point_collection,
};
};

let circloid = Circloid {
center: center,
base_radius: base_radius,
Expand Down Expand Up @@ -103,3 +125,21 @@ impl Circloid {
path
}
}

// Helpers
fn reorder_vec_to_0(point: Point, vec: &Vec<Point>) -> Option<Vec<Point>> {
if let Some(index) = vec.iter().position(|&r| r == point) {
let (before, after) = vec.split_at(index);
Some([after, before].concat())
} else {
None
}
}

fn find_smallest_angle(angle: f64) -> bool {
if angle > 6.27 && angle < 6.29 {
return true;
} else {
return false;
}
}
Binary file added title.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit b14bbfb

Please sign in to comment.