Only draw scene once
This commit is contained in:
parent
5cb9409723
commit
ef3253d777
1 changed files with 17 additions and 32 deletions
37
src/main.rs
37
src/main.rs
|
|
@ -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();
|
||||||
|
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(
|
scene.fill(
|
||||||
peniko::Fill::NonZero,
|
peniko::Fill::NonZero,
|
||||||
kurbo::Affine::default(),
|
kurbo::Affine::default(),
|
||||||
peniko::Color::WHITE,
|
peniko::Color::WHITE,
|
||||||
None,
|
None,
|
||||||
&kurbo::Circle::new(*point, 0.1),
|
&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);
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue