45 lines
1.2 KiB
Rust
45 lines
1.2 KiB
Rust
use bevy::prelude::*;
|
|
use bevy_vello::{VelloPlugin, prelude::*, vello::kurbo::Point};
|
|
use rand::Rng;
|
|
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(PostStartup, draw_map)
|
|
.run();
|
|
}
|
|
|
|
fn setup_vector_graphics(mut commands: Commands) {
|
|
commands.spawn((Camera2d, VelloView));
|
|
commands.spawn(VelloScene::new());
|
|
}
|
|
|
|
fn draw_map(mut query_scene: Single<(&mut Transform, &mut VelloScene)>) {
|
|
let (transform, scene) = query_scene.deref_mut();
|
|
// Reset scene every frame
|
|
scene.reset();
|
|
|
|
let mut rng = rand::rng();
|
|
for x in -20..=20 {
|
|
for y in -10..=10 {
|
|
let point = Point::new(
|
|
(x as f64) + rng.random_range(-JITTER..=JITTER),
|
|
(y as f64) + rng.random_range(-JITTER..=JITTER),
|
|
);
|
|
scene.fill(
|
|
peniko::Fill::NonZero,
|
|
kurbo::Affine::default(),
|
|
peniko::Color::WHITE,
|
|
None,
|
|
&kurbo::Circle::new(point, 0.1),
|
|
);
|
|
}
|
|
}
|
|
|
|
transform.scale = Vec3::ONE * 25.0;
|
|
}
|