use std::f32::consts::PI;
use bevy::prelude::*;
use bevy_retrograde::prelude::*;
fn main() {
App::build()
.insert_resource(WindowDescriptor {
title: "Bevy Retrograde Epaint Demo".into(),
..Default::default()
})
.add_plugins(RetroPlugins)
.add_startup_system(setup.system())
.add_system(move_diamond.system())
.run();
}
struct Diamond;
fn setup(mut commands: Commands) {
commands.spawn_bundle(CameraBundle {
camera: Camera {
size: CameraSize::FixedHeight(100),
background_color: Color::new(0.2, 0.2, 0.2, 1.0),
..Default::default()
},
..Default::default()
});
commands.spawn_bundle(ShapeBundle {
shape: Shape::circle_filled(epaint::emath::pos2(0., 0.), 5., epaint::Color32::BLUE),
..Default::default()
});
commands.spawn_bundle(ShapeBundle {
shape: Shape::rect_filled(
epaint::emath::Rect {
min: epaint::pos2(-20., -20.),
max: epaint::pos2(20., 20.),
},
1.,
epaint::Color32::RED,
),
transform: Transform::from_xyz(0., 0., -1.),
..Default::default()
});
commands
.spawn_bundle(ShapeBundle {
shape: Shape::closed_line(
vec![
epaint::pos2(0., -40.),
epaint::pos2(40., 0.),
epaint::pos2(0., 40.),
epaint::pos2(-40., 0.),
],
(1., epaint::Color32::GREEN),
),
..Default::default()
})
.insert(Diamond);
}
fn move_diamond(mut diamonds: Query<&mut Transform, With<Diamond>>, time: Res<Time>) {
for mut transform in diamonds.iter_mut() {
transform.scale = Vec3::splat((time.seconds_since_startup() as f32).sin() + 0.5);
transform.rotation = Quat::from_axis_angle(
Vec3::Z,
(time.seconds_since_startup() as f32).sin() * 2. * PI,
);
}
}