Only draw scene once

This commit is contained in:
Niklas Korz 2025-03-30 16:22:00 +02:00
parent 5cb9409723
commit ef3253d777

View file

@ -5,56 +5,41 @@ use std::ops::DerefMut;
const JITTER: f64 = 0.5; const JITTER: f64 = 0.5;
#[derive(Component)]
struct Grid {
points: Vec<Point>,
}
fn main() { fn main() {
App::new() App::new()
.add_plugins(DefaultPlugins) .add_plugins(DefaultPlugins)
.add_plugins(VelloPlugin::default()) .add_plugins(VelloPlugin::default())
.add_systems(Startup, setup_vector_graphics) .add_systems(Startup, setup_vector_graphics)
.add_systems(Update, simple_animation) .add_systems(PostStartup, draw_map)
.run(); .run();
} }
fn setup_vector_graphics(mut commands: Commands) { fn setup_vector_graphics(mut commands: Commands) {
commands.spawn((Camera2d, VelloView)); commands.spawn((Camera2d, VelloView));
commands.spawn(VelloScene::new()); 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( fn draw_map(mut query_scene: Single<(&mut Transform, &mut VelloScene)>) {
mut query_scene: Single<(&mut Transform, &mut VelloScene)>,
query_grid: Query<&Grid>,
) {
let (transform, scene) = query_scene.deref_mut(); let (transform, scene) = query_scene.deref_mut();
// Reset scene every frame // Reset scene every frame
scene.reset(); scene.reset();
for point in &query_grid.single().points { let mut rng = rand::rng();
scene.fill( for x in -20..=20 {
peniko::Fill::NonZero, for y in -10..=10 {
kurbo::Affine::default(), let point = Point::new(
peniko::Color::WHITE, (x as f64) + rng.random_range(-JITTER..=JITTER),
None, (y as f64) + rng.random_range(-JITTER..=JITTER),
&kurbo::Circle::new(*point, 0.1), );
); scene.fill(
peniko::Fill::NonZero,
kurbo::Affine::default(),
peniko::Color::WHITE,
None,
&kurbo::Circle::new(point, 0.1),
);
}
} }
transform.scale = Vec3::ONE * 25.0; transform.scale = Vec3::ONE * 25.0;
//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);
} }