From 5cb940972382b5bfc68bca8389fb8c381b57458b Mon Sep 17 00:00:00 2001 From: Niklas Korz Date: Sun, 30 Mar 2025 16:10:16 +0200 Subject: [PATCH 1/4] Generate random points --- Cargo.lock | 91 ++++++++++++++++++++++++++++++++++++++++++++++------- Cargo.toml | 1 + src/main.rs | 58 +++++++++++++++++++++------------- 3 files changed, 117 insertions(+), 33 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e4b45d9..8829e8d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -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", ] @@ -2877,6 +2889,7 @@ version = "0.1.0" dependencies = [ "bevy", "bevy_vello", + "rand 0.9.0", ] [[package]] @@ -3444,6 +3457,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 +3476,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 +3498,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 +3517,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 +3536,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "32cb0b9bc82b0a0876c2dd994a7e7a2683d3e7390ca40e6886785ef0c7e3ee31" dependencies = [ "num-traits", - "rand", + "rand 0.8.5", ] [[package]] @@ -4354,7 +4403,7 @@ version = "1.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b3758f5e68192bb96cc8f9b7e2c2cfdabb435499a28499a42f8f984092adad4b" dependencies = [ - "getrandom", + "getrandom 0.2.15", "serde", ] @@ -4463,6 +4512,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 +5251,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" diff --git a/Cargo.toml b/Cargo.toml index 0f87e70..e8494d3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,3 +14,4 @@ opt-level = 3 [dependencies] bevy = "0.15.3" bevy_vello = "0.7.1" +rand = "0.9.0" diff --git a/src/main.rs b/src/main.rs index a7f3301..8c6fa6b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,7 +1,15 @@ use bevy::prelude::*; -use bevy_vello::{VelloPlugin, prelude::*}; +use bevy_vello::{VelloPlugin, prelude::*, vello::kurbo::Point}; +use rand::Rng; use std::ops::DerefMut; +const JITTER: f64 = 0.5; + +#[derive(Component)] +struct Grid { + points: Vec, +} + fn main() { App::new() .add_plugins(DefaultPlugins) @@ -14,31 +22,39 @@ fn main() { fn setup_vector_graphics(mut commands: Commands) { commands.spawn((Camera2d, VelloView)); commands.spawn(VelloScene::new()); + + let mut rng = rand::rng(); + let mut points = Vec::new(); + for x in -20..=20 { + for y in -10..=10 { + points.push(Point::new( + (x as f64) + rng.random_range(-JITTER..=JITTER), + (y as f64) + rng.random_range(-JITTER..=JITTER), + )); + } + } + commands.spawn(Grid { points }); } -fn simple_animation(mut query_scene: Single<(&mut Transform, &mut VelloScene)>, time: Res