Compare commits
4 commits
ff438eae2c
...
ffbdb33659
| Author | SHA1 | Date | |
|---|---|---|---|
| ffbdb33659 | |||
| acd4a62d08 | |||
| ef3253d777 | |||
| 5cb9409723 |
3 changed files with 146 additions and 35 deletions
110
Cargo.lock
generated
110
Cargo.lock
generated
|
|
@ -75,7 +75,7 @@ checksum = "e89da841a80418a9b391ebaea17f5c112ffaaa96f621d2c285b5174da76b9011"
|
|||
dependencies = [
|
||||
"cfg-if",
|
||||
"const-random",
|
||||
"getrandom",
|
||||
"getrandom 0.2.15",
|
||||
"once_cell",
|
||||
"version_check",
|
||||
"zerocopy 0.7.35",
|
||||
|
|
@ -790,7 +790,7 @@ dependencies = [
|
|||
"derive_more",
|
||||
"glam",
|
||||
"itertools",
|
||||
"rand",
|
||||
"rand 0.8.5",
|
||||
"rand_distr",
|
||||
"serde",
|
||||
"smallvec",
|
||||
|
|
@ -1168,7 +1168,7 @@ checksum = "63c2174d43a0de99f863c98a472370047a2bfa7d1e5cec8d9d647fb500905d9d"
|
|||
dependencies = [
|
||||
"ahash",
|
||||
"bevy_utils_proc_macros",
|
||||
"getrandom",
|
||||
"getrandom 0.2.15",
|
||||
"hashbrown 0.14.5",
|
||||
"thread_local",
|
||||
"tracing",
|
||||
|
|
@ -1544,7 +1544,7 @@ version = "0.1.16"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f9d839f2a20b0aee515dc581a6172f2321f96cab76c1a38a4c584a194955390e"
|
||||
dependencies = [
|
||||
"getrandom",
|
||||
"getrandom 0.2.15",
|
||||
"once_cell",
|
||||
"tiny-keccak",
|
||||
]
|
||||
|
|
@ -2148,10 +2148,22 @@ dependencies = [
|
|||
"cfg-if",
|
||||
"js-sys",
|
||||
"libc",
|
||||
"wasi",
|
||||
"wasi 0.11.0+wasi-snapshot-preview1",
|
||||
"wasm-bindgen",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "getrandom"
|
||||
version = "0.3.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "73fea8450eea4bac3940448fb7ae50d91f034f941199fcd9d909a5a07aa455f0"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"libc",
|
||||
"r-efi",
|
||||
"wasi 0.14.2+wasi-0.2.4",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "gif"
|
||||
version = "0.13.1"
|
||||
|
|
@ -2214,7 +2226,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||
checksum = "dc46dd3ec48fdd8e693a98d2b8bafae273a2d54c1de02a2a7e3d57d501f39677"
|
||||
dependencies = [
|
||||
"bytemuck",
|
||||
"rand",
|
||||
"rand 0.8.5",
|
||||
"serde",
|
||||
]
|
||||
|
||||
|
|
@ -2696,6 +2708,15 @@ dependencies = [
|
|||
"regex-automata 0.1.10",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "maybe_parallel_iterator"
|
||||
version = "0.12.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5069b219d51d2ba2d9388623bd7eead5d4e7974bc8ff3ec9edbe36b09c0ef477"
|
||||
dependencies = [
|
||||
"rayon",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "memchr"
|
||||
version = "2.7.4"
|
||||
|
|
@ -2877,6 +2898,8 @@ version = "0.1.0"
|
|||
dependencies = [
|
||||
"bevy",
|
||||
"bevy_vello",
|
||||
"rand 0.9.0",
|
||||
"voronator",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
@ -3444,6 +3467,12 @@ dependencies = [
|
|||
"proc-macro2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "r-efi"
|
||||
version = "5.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "74765f6d916ee2faa39bc8e68e4f3ed8949b48cccdac59983d287a7cb71ce9c5"
|
||||
|
||||
[[package]]
|
||||
name = "radsort"
|
||||
version = "0.1.1"
|
||||
|
|
@ -3457,8 +3486,19 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||
checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"rand_chacha",
|
||||
"rand_core",
|
||||
"rand_chacha 0.3.1",
|
||||
"rand_core 0.6.4",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand"
|
||||
version = "0.9.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3779b94aeb87e8bd4e834cee3650289ee9e0d5677f976ecdb6d219e5f4f6cd94"
|
||||
dependencies = [
|
||||
"rand_chacha 0.9.0",
|
||||
"rand_core 0.9.3",
|
||||
"zerocopy 0.8.24",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
@ -3468,7 +3508,17 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||
checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88"
|
||||
dependencies = [
|
||||
"ppv-lite86",
|
||||
"rand_core",
|
||||
"rand_core 0.6.4",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand_chacha"
|
||||
version = "0.9.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d3022b5f1df60f26e1ffddd6c66e8aa15de382ae63b3a0c1bfc0e4d3e3f325cb"
|
||||
dependencies = [
|
||||
"ppv-lite86",
|
||||
"rand_core 0.9.3",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
@ -3477,7 +3527,16 @@ version = "0.6.4"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c"
|
||||
dependencies = [
|
||||
"getrandom",
|
||||
"getrandom 0.2.15",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand_core"
|
||||
version = "0.9.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "99d9a13982dcf210057a8a78572b2217b667c3beacbf3a0d8b454f6f82837d38"
|
||||
dependencies = [
|
||||
"getrandom 0.3.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
@ -3487,7 +3546,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||
checksum = "32cb0b9bc82b0a0876c2dd994a7e7a2683d3e7390ca40e6886785ef0c7e3ee31"
|
||||
dependencies = [
|
||||
"num-traits",
|
||||
"rand",
|
||||
"rand 0.8.5",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
@ -4354,7 +4413,7 @@ version = "1.12.1"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b3758f5e68192bb96cc8f9b7e2c2cfdabb435499a28499a42f8f984092adad4b"
|
||||
dependencies = [
|
||||
"getrandom",
|
||||
"getrandom 0.2.15",
|
||||
"serde",
|
||||
]
|
||||
|
||||
|
|
@ -4447,6 +4506,15 @@ version = "0.9.5"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a"
|
||||
|
||||
[[package]]
|
||||
name = "voronator"
|
||||
version = "0.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "07d8e6fe4b9b3b443f2e4ada327cf4b08ab5cdd27a42cd5c9f38dd29092c10ee"
|
||||
dependencies = [
|
||||
"maybe_parallel_iterator",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "walkdir"
|
||||
version = "2.5.0"
|
||||
|
|
@ -4463,6 +4531,15 @@ version = "0.11.0+wasi-snapshot-preview1"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"
|
||||
|
||||
[[package]]
|
||||
name = "wasi"
|
||||
version = "0.14.2+wasi-0.2.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9683f9a5a998d873c0d21fcbe3c083009670149a8fab228644b8bd36b2c48cb3"
|
||||
dependencies = [
|
||||
"wit-bindgen-rt",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen"
|
||||
version = "0.2.100"
|
||||
|
|
@ -5193,6 +5270,15 @@ dependencies = [
|
|||
"memchr",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wit-bindgen-rt"
|
||||
version = "0.39.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6f42320e61fe2cfd34354ecb597f86f413484a798ba44a8ca1165c58d42da6c1"
|
||||
dependencies = [
|
||||
"bitflags 2.9.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "x11-dl"
|
||||
version = "2.21.0"
|
||||
|
|
|
|||
|
|
@ -14,3 +14,5 @@ opt-level = 3
|
|||
[dependencies]
|
||||
bevy = "0.15.3"
|
||||
bevy_vello = "0.7.1"
|
||||
rand = "0.9.0"
|
||||
voronator = "0.2.1"
|
||||
|
|
|
|||
69
src/main.rs
69
src/main.rs
|
|
@ -1,13 +1,21 @@
|
|||
use bevy::prelude::*;
|
||||
use bevy_vello::{VelloPlugin, prelude::*};
|
||||
use bevy_vello::{
|
||||
VelloPlugin,
|
||||
prelude::*,
|
||||
vello::kurbo::{PathEl, Point},
|
||||
};
|
||||
use rand::Rng;
|
||||
use voronator::VoronoiDiagram;
|
||||
use std::ops::DerefMut;
|
||||
|
||||
const JITTER: f64 = 0.5;
|
||||
|
||||
fn main() {
|
||||
App::new()
|
||||
.add_plugins(DefaultPlugins)
|
||||
.add_plugins(VelloPlugin::default())
|
||||
.add_systems(Startup, setup_vector_graphics)
|
||||
.add_systems(Update, simple_animation)
|
||||
.add_systems(PostStartup, draw_map)
|
||||
.run();
|
||||
}
|
||||
|
||||
|
|
@ -16,29 +24,44 @@ fn setup_vector_graphics(mut commands: Commands) {
|
|||
commands.spawn(VelloScene::new());
|
||||
}
|
||||
|
||||
fn simple_animation(mut query_scene: Single<(&mut Transform, &mut VelloScene)>, time: Res<Time>) {
|
||||
let sin_time = time.elapsed_secs().sin().mul_add(0.5, 0.5);
|
||||
fn draw_map(mut query_scene: Single<(&mut Transform, &mut VelloScene)>) {
|
||||
let (transform, scene) = query_scene.deref_mut();
|
||||
// Reset scene every frame
|
||||
scene.reset();
|
||||
transform.scale = Vec3::ONE * 30.0;
|
||||
|
||||
// Animate color green to blue
|
||||
let c = Vec3::lerp(
|
||||
Vec3::new(-1.0, 1.0, -1.0),
|
||||
Vec3::new(-1.0, 1.0, 1.0),
|
||||
sin_time + 0.5,
|
||||
);
|
||||
let mut rng = rand::rng();
|
||||
let mut points = Vec::new();
|
||||
for x in -20..=20 {
|
||||
for y in -10..=10 {
|
||||
points.push((
|
||||
(x as f64) + rng.random_range(-JITTER..=JITTER),
|
||||
(y as f64) + rng.random_range(-JITTER..=JITTER),
|
||||
));
|
||||
}
|
||||
}
|
||||
let diagram = VoronoiDiagram::<voronator::delaunator::Point>::from_tuple(&(-20.0, -10.0), &(20.0, 10.0), &points).unwrap();
|
||||
|
||||
// Animate the corner radius
|
||||
scene.fill(
|
||||
peniko::Fill::NonZero,
|
||||
kurbo::Affine::default(),
|
||||
peniko::Color::new([c.x, c.y, c.z, 1.]),
|
||||
None,
|
||||
&kurbo::RoundedRect::new(-50.0, -50.0, 50.0, 50.0, (sin_time as f64) * 50.0),
|
||||
);
|
||||
|
||||
transform.scale = Vec3::lerp(Vec3::ONE * 0.5, Vec3::ONE * 1.0, sin_time);
|
||||
transform.translation = Vec3::lerp(Vec3::X * -100.0, Vec3::X * 100.0, sin_time);
|
||||
transform.rotation = Quat::from_rotation_z(-std::f32::consts::TAU * sin_time);
|
||||
for cell in diagram.cells() {
|
||||
let mut first = true;
|
||||
let mut path = Vec::new();
|
||||
for point in cell.points() {
|
||||
let point = Point::new(point.x, point.y);
|
||||
if first {
|
||||
first = false;
|
||||
path.push(PathEl::MoveTo(point));
|
||||
} else {
|
||||
path.push(PathEl::LineTo(point));
|
||||
}
|
||||
}
|
||||
let r = rng.random_range(0..=255);
|
||||
let g = rng.random_range(0..=255);
|
||||
let b = rng.random_range(0..=255);
|
||||
scene.fill(
|
||||
peniko::Fill::NonZero,
|
||||
kurbo::Affine::default(),
|
||||
peniko::Color::from_rgb8(r, g, b),
|
||||
None,
|
||||
&kurbo::BezPath::from_vec(path),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue