2023-03-20 20:57:54 +00:00
|
|
|
//! This example demonstrates Bevy's immediate mode drawing API intended for visual debugging.
|
|
|
|
|
2023-04-21 15:34:07 +00:00
|
|
|
use std::f32::consts::PI;
|
|
|
|
|
2023-03-20 20:57:54 +00:00
|
|
|
use bevy::prelude::*;
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
App::new()
|
|
|
|
.add_plugins(DefaultPlugins)
|
|
|
|
.add_systems(Startup, setup)
|
2023-06-13 06:49:47 +00:00
|
|
|
.add_systems(Update, (system, update_config))
|
2023-03-20 20:57:54 +00:00
|
|
|
.run();
|
|
|
|
}
|
|
|
|
|
2023-06-13 06:49:47 +00:00
|
|
|
fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
|
2023-03-20 20:57:54 +00:00
|
|
|
commands.spawn(Camera2dBundle::default());
|
2023-06-13 06:49:47 +00:00
|
|
|
// text
|
|
|
|
commands.spawn(TextBundle::from_section(
|
|
|
|
"Hold 'Left' or 'Right' to change the line width",
|
|
|
|
TextStyle {
|
|
|
|
font: asset_server.load("fonts/FiraMono-Medium.ttf"),
|
|
|
|
font_size: 24.,
|
|
|
|
color: Color::WHITE,
|
|
|
|
},
|
|
|
|
));
|
2023-03-20 20:57:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn system(mut gizmos: Gizmos, time: Res<Time>) {
|
|
|
|
let sin = time.elapsed_seconds().sin() * 50.;
|
|
|
|
gizmos.line_2d(Vec2::Y * -sin, Vec2::splat(-80.), Color::RED);
|
|
|
|
gizmos.ray_2d(Vec2::Y * sin, Vec2::splat(80.), Color::GREEN);
|
|
|
|
|
|
|
|
// Triangle
|
|
|
|
gizmos.linestrip_gradient_2d([
|
|
|
|
(Vec2::Y * 300., Color::BLUE),
|
|
|
|
(Vec2::new(-255., -155.), Color::RED),
|
|
|
|
(Vec2::new(255., -155.), Color::GREEN),
|
|
|
|
(Vec2::Y * 300., Color::BLUE),
|
|
|
|
]);
|
|
|
|
|
|
|
|
gizmos.rect_2d(
|
|
|
|
Vec2::ZERO,
|
|
|
|
time.elapsed_seconds() / 3.,
|
|
|
|
Vec2::splat(300.),
|
|
|
|
Color::BLACK,
|
|
|
|
);
|
|
|
|
|
|
|
|
// The circles have 32 line-segments by default.
|
|
|
|
gizmos.circle_2d(Vec2::ZERO, 120., Color::BLACK);
|
|
|
|
// You may want to increase this for larger circles.
|
|
|
|
gizmos.circle_2d(Vec2::ZERO, 300., Color::NAVY).segments(64);
|
2023-04-21 15:34:07 +00:00
|
|
|
|
2023-08-12 21:06:15 +00:00
|
|
|
// Arcs default amount of segments is linearly interpolated between
|
2023-04-21 15:34:07 +00:00
|
|
|
// 1 and 32, using the arc length as scalar.
|
|
|
|
gizmos.arc_2d(Vec2::ZERO, sin / 10., PI / 2., 350., Color::ORANGE_RED);
|
2023-11-15 14:19:15 +00:00
|
|
|
|
|
|
|
gizmos.arrow_2d(
|
|
|
|
Vec2::ZERO,
|
|
|
|
Vec2::from_angle(sin / -10. + PI / 2.) * 50.,
|
|
|
|
Color::YELLOW,
|
|
|
|
);
|
2023-03-20 20:57:54 +00:00
|
|
|
}
|
2023-06-13 06:49:47 +00:00
|
|
|
|
|
|
|
fn update_config(mut config: ResMut<GizmoConfig>, keyboard: Res<Input<KeyCode>>, time: Res<Time>) {
|
|
|
|
if keyboard.pressed(KeyCode::Right) {
|
|
|
|
config.line_width += 5. * time.delta_seconds();
|
|
|
|
}
|
|
|
|
if keyboard.pressed(KeyCode::Left) {
|
|
|
|
config.line_width -= 5. * time.delta_seconds();
|
|
|
|
}
|
|
|
|
}
|