easing_functions example: draw point closer to its curve (#15744)
# 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
This commit is contained in:
parent
dec52a0c8f
commit
26813d9732
@ -88,7 +88,7 @@ fn setup(mut commands: Commands) {
|
|||||||
color,
|
color,
|
||||||
..default()
|
..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()
|
..default()
|
||||||
});
|
});
|
||||||
p.spawn(SpriteBundle {
|
p.spawn(SpriteBundle {
|
||||||
@ -113,6 +113,8 @@ fn setup(mut commands: Commands) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const SIZE_PER_FUNCTION: f32 = 95.0;
|
||||||
|
|
||||||
fn display_curves(
|
fn display_curves(
|
||||||
mut gizmos: Gizmos,
|
mut gizmos: Gizmos,
|
||||||
ease_functions: Query<(&SelectedEaseFunction, &Transform, &Children)>,
|
ease_functions: Query<(&SelectedEaseFunction, &Transform, &Children)>,
|
||||||
@ -121,7 +123,6 @@ fn display_curves(
|
|||||||
time: Res<Time>,
|
time: Res<Time>,
|
||||||
) {
|
) {
|
||||||
let samples = 100;
|
let samples = 100;
|
||||||
let size = 95.0;
|
|
||||||
let duration = 2.5;
|
let duration = 2.5;
|
||||||
let time_margin = 0.5;
|
let time_margin = 0.5;
|
||||||
|
|
||||||
@ -136,16 +137,16 @@ fn display_curves(
|
|||||||
[
|
[
|
||||||
Vec2::new(transform.translation.x, transform.translation.y + 15.0),
|
Vec2::new(transform.translation.x, transform.translation.y + 15.0),
|
||||||
Vec2::new(
|
Vec2::new(
|
||||||
transform.translation.x + size,
|
transform.translation.x + SIZE_PER_FUNCTION,
|
||||||
transform.translation.y + 15.0,
|
transform.translation.y + 15.0,
|
||||||
),
|
),
|
||||||
Vec2::new(
|
Vec2::new(
|
||||||
transform.translation.x + size,
|
transform.translation.x + SIZE_PER_FUNCTION,
|
||||||
transform.translation.y + 15.0 + size,
|
transform.translation.y + 15.0 + SIZE_PER_FUNCTION,
|
||||||
),
|
),
|
||||||
Vec2::new(
|
Vec2::new(
|
||||||
transform.translation.x,
|
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),
|
Vec2::new(transform.translation.x, transform.translation.y + 15.0),
|
||||||
],
|
],
|
||||||
@ -156,8 +157,8 @@ fn display_curves(
|
|||||||
let f = easing_curve(0.0, 1.0, *function);
|
let f = easing_curve(0.0, 1.0, *function);
|
||||||
let drawn_curve = f.by_ref().graph().map(|(x, y)| {
|
let drawn_curve = f.by_ref().graph().map(|(x, y)| {
|
||||||
Vec2::new(
|
Vec2::new(
|
||||||
x * size + transform.translation.x,
|
x * SIZE_PER_FUNCTION + transform.translation.x,
|
||||||
y * size + transform.translation.y + 15.0,
|
y * SIZE_PER_FUNCTION + transform.translation.y + 15.0,
|
||||||
)
|
)
|
||||||
});
|
});
|
||||||
gizmos.curve_2d(
|
gizmos.curve_2d(
|
||||||
@ -167,13 +168,17 @@ fn display_curves(
|
|||||||
);
|
);
|
||||||
|
|
||||||
// Show progress along the curve for the current time
|
// 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[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(
|
gizmos.linestrip_2d(
|
||||||
[
|
[
|
||||||
Vec2::new(transform.translation.x, transform.translation.y + y),
|
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),
|
color.darker(0.2),
|
||||||
);
|
);
|
||||||
|
Loading…
Reference in New Issue
Block a user