smoothing/
smoothing.rs

1use bevy::prelude::*;
2use press_here::{AppExt, AxisVisualizer, Deadzone, Pair, Smooth};
3use std::time::Duration;
4
5fn main() {
6    let bindings = (
7        Pair(KeyCode::KeyA, KeyCode::KeyD),
8        Deadzone(GamepadAxis::LeftStickX, 0.1),
9    );
10    App::new()
11        .add_plugins(DefaultPlugins)
12        .add_axis::<Unsmoothed>(bindings)
13        .add_axis::<Smoothed>(Smooth::new(bindings, 0.1))
14        .add_systems(Startup, setup)
15        .add_systems(Update, test)
16        .run();
17}
18
19pub struct Unsmoothed;
20pub struct Smoothed;
21
22fn test(
23    mut unsmoothed_visualizer: AxisVisualizer<Unsmoothed>,
24    mut smoothed_visualizer: AxisVisualizer<Smoothed>,
25) {
26    unsmoothed_visualizer.graph_x(
27        Duration::from_secs_f32(5.0),
28        Vec2::ZERO,
29        100.0,
30        Vec2::new(400.0, 200.0),
31        Srgba::RED,
32    );
33    smoothed_visualizer.graph_x(
34        Duration::from_secs_f32(5.0),
35        Vec2::ZERO,
36        100.0,
37        Vec2::new(400.0, 200.0),
38        Srgba::GREEN,
39    );
40}
41
42fn setup(mut commands: Commands) {
43    commands.spawn(Camera2d);
44}