Replace Voronoi diagram with Barycentric dual mesh
This commit is contained in:
parent
542708b439
commit
fe9407cbb2
1 changed files with 8 additions and 12 deletions
20
src/main.rs
20
src/main.rs
|
|
@ -7,7 +7,7 @@ use bevy_vello::{
|
||||||
use fast_poisson::Poisson2D;
|
use fast_poisson::Poisson2D;
|
||||||
use noise::{NoiseFn, Simplex};
|
use noise::{NoiseFn, Simplex};
|
||||||
use std::{ops::DerefMut, time::SystemTime};
|
use std::{ops::DerefMut, time::SystemTime};
|
||||||
use voronator::VoronoiDiagram;
|
use voronator::CentroidDiagram;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
App::new()
|
App::new()
|
||||||
|
|
@ -27,27 +27,23 @@ fn draw_map(mut query_scene: Single<(&mut Transform, &mut VelloScene)>) {
|
||||||
let (transform, scene) = query_scene.deref_mut();
|
let (transform, scene) = query_scene.deref_mut();
|
||||||
scene.reset();
|
scene.reset();
|
||||||
|
|
||||||
let grid_size_x = 20.0;
|
let grid_size_x = 120.0;
|
||||||
let grid_size_y = 10.0;
|
let grid_size_y = 60.0;
|
||||||
|
|
||||||
let points: Vec<_> = Poisson2D::new()
|
let points: Vec<_> = Poisson2D::new()
|
||||||
.with_dimensions([grid_size_x, grid_size_y], 0.2)
|
.with_dimensions([grid_size_x, grid_size_y], 1.0)
|
||||||
.iter()
|
.iter()
|
||||||
.map(|[x, y]| (x, y))
|
.map(|[x, y]| (x, y))
|
||||||
.collect();
|
.collect();
|
||||||
let diagram = VoronoiDiagram::<voronator::delaunator::Point>::from_tuple(
|
// Barycentric dual mesh
|
||||||
&(0.0, 0.0),
|
let mesh = CentroidDiagram::<voronator::delaunator::Point>::from_tuple(&points).unwrap();
|
||||||
&(grid_size_x, grid_size_y),
|
|
||||||
&points,
|
|
||||||
)
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let seed = SystemTime::now()
|
let seed = SystemTime::now()
|
||||||
.duration_since(SystemTime::UNIX_EPOCH)
|
.duration_since(SystemTime::UNIX_EPOCH)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.as_secs() as u32;
|
.as_secs() as u32;
|
||||||
let noise = Simplex::new(seed);
|
let noise = Simplex::new(seed);
|
||||||
for cell in diagram.cells() {
|
for cell in &mesh.cells {
|
||||||
let mut first = true;
|
let mut first = true;
|
||||||
let mut path = Vec::new();
|
let mut path = Vec::new();
|
||||||
let mut center = Point::new(0.0, 0.0);
|
let mut center = Point::new(0.0, 0.0);
|
||||||
|
|
@ -85,7 +81,7 @@ fn draw_map(mut query_scene: Single<(&mut Transform, &mut VelloScene)>) {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
let scale = 60.0;
|
let scale = 10.0;
|
||||||
transform.scale = Vec3::ONE * scale;
|
transform.scale = Vec3::ONE * scale;
|
||||||
transform.translation =
|
transform.translation =
|
||||||
Vec3::new(-(grid_size_x as f32 / 2.0), grid_size_y as f32 / 2.0, 0.0) * scale;
|
Vec3::new(-(grid_size_x as f32 / 2.0), grid_size_y as f32 / 2.0, 0.0) * scale;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue