Skip to content

Commit

Permalink
easing_functions example: draw point closer to its curve (#15744)
Browse files Browse the repository at this point in the history
# Objective

- After #15711 which added a column to the example, the point of a curve
was too close to the next curve

## Solution

- Make it closer to its own
  • Loading branch information
mockersf authored Oct 8, 2024
1 parent dec52a0 commit 26813d9
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions examples/animation/easing_functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ fn setup(mut commands: Commands) {
color,
..default()
},
transform: Transform::from_xyz(110.0, 15.0, 0.0),
transform: Transform::from_xyz(SIZE_PER_FUNCTION + 5.0, 15.0, 0.0),
..default()
});
p.spawn(SpriteBundle {
Expand All @@ -113,6 +113,8 @@ fn setup(mut commands: Commands) {
);
}

const SIZE_PER_FUNCTION: f32 = 95.0;

fn display_curves(
mut gizmos: Gizmos,
ease_functions: Query<(&SelectedEaseFunction, &Transform, &Children)>,
Expand All @@ -121,7 +123,6 @@ fn display_curves(
time: Res<Time>,
) {
let samples = 100;
let size = 95.0;
let duration = 2.5;
let time_margin = 0.5;

Expand All @@ -136,16 +137,16 @@ fn display_curves(
[
Vec2::new(transform.translation.x, transform.translation.y + 15.0),
Vec2::new(
transform.translation.x + size,
transform.translation.x + SIZE_PER_FUNCTION,
transform.translation.y + 15.0,
),
Vec2::new(
transform.translation.x + size,
transform.translation.y + 15.0 + size,
transform.translation.x + SIZE_PER_FUNCTION,
transform.translation.y + 15.0 + SIZE_PER_FUNCTION,
),
Vec2::new(
transform.translation.x,
transform.translation.y + 15.0 + size,
transform.translation.y + 15.0 + SIZE_PER_FUNCTION,
),
Vec2::new(transform.translation.x, transform.translation.y + 15.0),
],
Expand All @@ -156,8 +157,8 @@ fn display_curves(
let f = easing_curve(0.0, 1.0, *function);
let drawn_curve = f.by_ref().graph().map(|(x, y)| {
Vec2::new(
x * size + transform.translation.x,
y * size + transform.translation.y + 15.0,
x * SIZE_PER_FUNCTION + transform.translation.x,
y * SIZE_PER_FUNCTION + transform.translation.y + 15.0,
)
});
gizmos.curve_2d(
Expand All @@ -167,13 +168,17 @@ fn display_curves(
);

// Show progress along the curve for the current time
let y = f.sample(now).unwrap() * size + 15.0;
let y = f.sample(now).unwrap() * SIZE_PER_FUNCTION + 15.0;
transforms.get_mut(children[0]).unwrap().translation.y = y;
transforms.get_mut(children[1]).unwrap().translation = Vec3::new(now * size, y, 0.0);
transforms.get_mut(children[1]).unwrap().translation =
Vec3::new(now * SIZE_PER_FUNCTION, y, 0.0);
gizmos.linestrip_2d(
[
Vec2::new(transform.translation.x, transform.translation.y + y),
Vec2::new(transform.translation.x + size, transform.translation.y + y),
Vec2::new(
transform.translation.x + SIZE_PER_FUNCTION,
transform.translation.y + y,
),
],
color.darker(0.2),
);
Expand Down

0 comments on commit 26813d9

Please sign in to comment.