diff --git a/crates/bevy_math/images/easefunction/BackIn.svg b/crates/bevy_math/images/easefunction/BackIn.svg new file mode 100644 index 0000000000..63a776ea4a --- /dev/null +++ b/crates/bevy_math/images/easefunction/BackIn.svg @@ -0,0 +1,5 @@ + +BackIn + + + \ No newline at end of file diff --git a/crates/bevy_math/images/easefunction/BackInOut.svg b/crates/bevy_math/images/easefunction/BackInOut.svg new file mode 100644 index 0000000000..8695c42f71 --- /dev/null +++ b/crates/bevy_math/images/easefunction/BackInOut.svg @@ -0,0 +1,5 @@ + +BackInOut + + + \ No newline at end of file diff --git a/crates/bevy_math/images/easefunction/BackOut.svg b/crates/bevy_math/images/easefunction/BackOut.svg new file mode 100644 index 0000000000..9479d0311b --- /dev/null +++ b/crates/bevy_math/images/easefunction/BackOut.svg @@ -0,0 +1,5 @@ + +BackOut + + + \ No newline at end of file diff --git a/crates/bevy_math/images/easefunction/BounceIn.svg b/crates/bevy_math/images/easefunction/BounceIn.svg new file mode 100644 index 0000000000..e5c22a6095 --- /dev/null +++ b/crates/bevy_math/images/easefunction/BounceIn.svg @@ -0,0 +1,5 @@ + +BounceIn + + + \ No newline at end of file diff --git a/crates/bevy_math/images/easefunction/BounceInOut.svg b/crates/bevy_math/images/easefunction/BounceInOut.svg new file mode 100644 index 0000000000..9aaf4e1e0a --- /dev/null +++ b/crates/bevy_math/images/easefunction/BounceInOut.svg @@ -0,0 +1,5 @@ + +BounceInOut + + + \ No newline at end of file diff --git a/crates/bevy_math/images/easefunction/BounceOut.svg b/crates/bevy_math/images/easefunction/BounceOut.svg new file mode 100644 index 0000000000..080eb0d198 --- /dev/null +++ b/crates/bevy_math/images/easefunction/BounceOut.svg @@ -0,0 +1,5 @@ + +BounceOut + + + \ No newline at end of file diff --git a/crates/bevy_math/images/easefunction/CircularIn.svg b/crates/bevy_math/images/easefunction/CircularIn.svg new file mode 100644 index 0000000000..3d8c7e0579 --- /dev/null +++ b/crates/bevy_math/images/easefunction/CircularIn.svg @@ -0,0 +1,5 @@ + +CircularIn + + + \ No newline at end of file diff --git a/crates/bevy_math/images/easefunction/CircularInOut.svg b/crates/bevy_math/images/easefunction/CircularInOut.svg new file mode 100644 index 0000000000..de2de720eb --- /dev/null +++ b/crates/bevy_math/images/easefunction/CircularInOut.svg @@ -0,0 +1,5 @@ + +CircularInOut + + + \ No newline at end of file diff --git a/crates/bevy_math/images/easefunction/CircularOut.svg b/crates/bevy_math/images/easefunction/CircularOut.svg new file mode 100644 index 0000000000..740a59cd68 --- /dev/null +++ b/crates/bevy_math/images/easefunction/CircularOut.svg @@ -0,0 +1,5 @@ + +CircularOut + + + \ No newline at end of file diff --git a/crates/bevy_math/images/easefunction/CubicIn.svg b/crates/bevy_math/images/easefunction/CubicIn.svg new file mode 100644 index 0000000000..f8acbc762a --- /dev/null +++ b/crates/bevy_math/images/easefunction/CubicIn.svg @@ -0,0 +1,5 @@ + +CubicIn + + + \ No newline at end of file diff --git a/crates/bevy_math/images/easefunction/CubicInOut.svg b/crates/bevy_math/images/easefunction/CubicInOut.svg new file mode 100644 index 0000000000..3fa5859f94 --- /dev/null +++ b/crates/bevy_math/images/easefunction/CubicInOut.svg @@ -0,0 +1,5 @@ + +CubicInOut + + + \ No newline at end of file diff --git a/crates/bevy_math/images/easefunction/CubicOut.svg b/crates/bevy_math/images/easefunction/CubicOut.svg new file mode 100644 index 0000000000..1c4f1abc55 --- /dev/null +++ b/crates/bevy_math/images/easefunction/CubicOut.svg @@ -0,0 +1,5 @@ + +CubicOut + + + \ No newline at end of file diff --git a/crates/bevy_math/images/easefunction/Elastic.svg b/crates/bevy_math/images/easefunction/Elastic.svg new file mode 100644 index 0000000000..fa187328cb --- /dev/null +++ b/crates/bevy_math/images/easefunction/Elastic.svg @@ -0,0 +1,5 @@ + +Elastic(50.0) + + + \ No newline at end of file diff --git a/crates/bevy_math/images/easefunction/ElasticIn.svg b/crates/bevy_math/images/easefunction/ElasticIn.svg new file mode 100644 index 0000000000..faa95a79a2 --- /dev/null +++ b/crates/bevy_math/images/easefunction/ElasticIn.svg @@ -0,0 +1,5 @@ + +ElasticIn + + + \ No newline at end of file diff --git a/crates/bevy_math/images/easefunction/ElasticInOut.svg b/crates/bevy_math/images/easefunction/ElasticInOut.svg new file mode 100644 index 0000000000..e0f0527a4f --- /dev/null +++ b/crates/bevy_math/images/easefunction/ElasticInOut.svg @@ -0,0 +1,5 @@ + +ElasticInOut + + + \ No newline at end of file diff --git a/crates/bevy_math/images/easefunction/ElasticOut.svg b/crates/bevy_math/images/easefunction/ElasticOut.svg new file mode 100644 index 0000000000..17817a6712 --- /dev/null +++ b/crates/bevy_math/images/easefunction/ElasticOut.svg @@ -0,0 +1,5 @@ + +ElasticOut + + + \ No newline at end of file diff --git a/crates/bevy_math/images/easefunction/ExponentialIn.svg b/crates/bevy_math/images/easefunction/ExponentialIn.svg new file mode 100644 index 0000000000..784cc6ccd5 --- /dev/null +++ b/crates/bevy_math/images/easefunction/ExponentialIn.svg @@ -0,0 +1,5 @@ + +ExponentialIn + + + \ No newline at end of file diff --git a/crates/bevy_math/images/easefunction/ExponentialInOut.svg b/crates/bevy_math/images/easefunction/ExponentialInOut.svg new file mode 100644 index 0000000000..3cc55941b0 --- /dev/null +++ b/crates/bevy_math/images/easefunction/ExponentialInOut.svg @@ -0,0 +1,5 @@ + +ExponentialInOut + + + \ No newline at end of file diff --git a/crates/bevy_math/images/easefunction/ExponentialOut.svg b/crates/bevy_math/images/easefunction/ExponentialOut.svg new file mode 100644 index 0000000000..0fb9f8720e --- /dev/null +++ b/crates/bevy_math/images/easefunction/ExponentialOut.svg @@ -0,0 +1,5 @@ + +ExponentialOut + + + \ No newline at end of file diff --git a/crates/bevy_math/images/easefunction/Linear.svg b/crates/bevy_math/images/easefunction/Linear.svg new file mode 100644 index 0000000000..99adedf3e8 --- /dev/null +++ b/crates/bevy_math/images/easefunction/Linear.svg @@ -0,0 +1,5 @@ + +Linear + + + \ No newline at end of file diff --git a/crates/bevy_math/images/easefunction/QuadraticIn.svg b/crates/bevy_math/images/easefunction/QuadraticIn.svg new file mode 100644 index 0000000000..15ba440314 --- /dev/null +++ b/crates/bevy_math/images/easefunction/QuadraticIn.svg @@ -0,0 +1,5 @@ + +QuadraticIn + + + \ No newline at end of file diff --git a/crates/bevy_math/images/easefunction/QuadraticInOut.svg b/crates/bevy_math/images/easefunction/QuadraticInOut.svg new file mode 100644 index 0000000000..f2f1098aae --- /dev/null +++ b/crates/bevy_math/images/easefunction/QuadraticInOut.svg @@ -0,0 +1,5 @@ + +QuadraticInOut + + + \ No newline at end of file diff --git a/crates/bevy_math/images/easefunction/QuadraticOut.svg b/crates/bevy_math/images/easefunction/QuadraticOut.svg new file mode 100644 index 0000000000..5b9d9a1b6c --- /dev/null +++ b/crates/bevy_math/images/easefunction/QuadraticOut.svg @@ -0,0 +1,5 @@ + +QuadraticOut + + + \ No newline at end of file diff --git a/crates/bevy_math/images/easefunction/QuarticIn.svg b/crates/bevy_math/images/easefunction/QuarticIn.svg new file mode 100644 index 0000000000..6028e35542 --- /dev/null +++ b/crates/bevy_math/images/easefunction/QuarticIn.svg @@ -0,0 +1,5 @@ + +QuarticIn + + + \ No newline at end of file diff --git a/crates/bevy_math/images/easefunction/QuarticInOut.svg b/crates/bevy_math/images/easefunction/QuarticInOut.svg new file mode 100644 index 0000000000..7afd6c74b4 --- /dev/null +++ b/crates/bevy_math/images/easefunction/QuarticInOut.svg @@ -0,0 +1,5 @@ + +QuarticInOut + + + \ No newline at end of file diff --git a/crates/bevy_math/images/easefunction/QuarticOut.svg b/crates/bevy_math/images/easefunction/QuarticOut.svg new file mode 100644 index 0000000000..f9fac71535 --- /dev/null +++ b/crates/bevy_math/images/easefunction/QuarticOut.svg @@ -0,0 +1,5 @@ + +QuarticOut + + + \ No newline at end of file diff --git a/crates/bevy_math/images/easefunction/QuinticIn.svg b/crates/bevy_math/images/easefunction/QuinticIn.svg new file mode 100644 index 0000000000..9dfaa926bf --- /dev/null +++ b/crates/bevy_math/images/easefunction/QuinticIn.svg @@ -0,0 +1,5 @@ + +QuinticIn + + + \ No newline at end of file diff --git a/crates/bevy_math/images/easefunction/QuinticInOut.svg b/crates/bevy_math/images/easefunction/QuinticInOut.svg new file mode 100644 index 0000000000..732b9db365 --- /dev/null +++ b/crates/bevy_math/images/easefunction/QuinticInOut.svg @@ -0,0 +1,5 @@ + +QuinticInOut + + + \ No newline at end of file diff --git a/crates/bevy_math/images/easefunction/QuinticOut.svg b/crates/bevy_math/images/easefunction/QuinticOut.svg new file mode 100644 index 0000000000..76da9d2e9f --- /dev/null +++ b/crates/bevy_math/images/easefunction/QuinticOut.svg @@ -0,0 +1,5 @@ + +QuinticOut + + + \ No newline at end of file diff --git a/crates/bevy_math/images/easefunction/README.md b/crates/bevy_math/images/easefunction/README.md new file mode 100644 index 0000000000..e341ea0e14 --- /dev/null +++ b/crates/bevy_math/images/easefunction/README.md @@ -0,0 +1,3 @@ +# EaseFunction + +These graphs are auto-generated via `tools/build-easefunction-graphs`. diff --git a/crates/bevy_math/images/easefunction/SineIn.svg b/crates/bevy_math/images/easefunction/SineIn.svg new file mode 100644 index 0000000000..e9630ca1d8 --- /dev/null +++ b/crates/bevy_math/images/easefunction/SineIn.svg @@ -0,0 +1,5 @@ + +SineIn + + + \ No newline at end of file diff --git a/crates/bevy_math/images/easefunction/SineInOut.svg b/crates/bevy_math/images/easefunction/SineInOut.svg new file mode 100644 index 0000000000..20e251e7da --- /dev/null +++ b/crates/bevy_math/images/easefunction/SineInOut.svg @@ -0,0 +1,5 @@ + +SineInOut + + + \ No newline at end of file diff --git a/crates/bevy_math/images/easefunction/SineOut.svg b/crates/bevy_math/images/easefunction/SineOut.svg new file mode 100644 index 0000000000..2cf451d784 --- /dev/null +++ b/crates/bevy_math/images/easefunction/SineOut.svg @@ -0,0 +1,5 @@ + +SineOut + + + \ No newline at end of file diff --git a/crates/bevy_math/images/easefunction/SmoothStep.svg b/crates/bevy_math/images/easefunction/SmoothStep.svg new file mode 100644 index 0000000000..74d8770317 --- /dev/null +++ b/crates/bevy_math/images/easefunction/SmoothStep.svg @@ -0,0 +1,5 @@ + +SmoothStep + + + \ No newline at end of file diff --git a/crates/bevy_math/images/easefunction/SmoothStepIn.svg b/crates/bevy_math/images/easefunction/SmoothStepIn.svg new file mode 100644 index 0000000000..84363c6448 --- /dev/null +++ b/crates/bevy_math/images/easefunction/SmoothStepIn.svg @@ -0,0 +1,5 @@ + +SmoothStepIn + + + \ No newline at end of file diff --git a/crates/bevy_math/images/easefunction/SmoothStepOut.svg b/crates/bevy_math/images/easefunction/SmoothStepOut.svg new file mode 100644 index 0000000000..09256cbd65 --- /dev/null +++ b/crates/bevy_math/images/easefunction/SmoothStepOut.svg @@ -0,0 +1,5 @@ + +SmoothStepOut + + + \ No newline at end of file diff --git a/crates/bevy_math/images/easefunction/SmootherStep.svg b/crates/bevy_math/images/easefunction/SmootherStep.svg new file mode 100644 index 0000000000..9c00abead6 --- /dev/null +++ b/crates/bevy_math/images/easefunction/SmootherStep.svg @@ -0,0 +1,5 @@ + +SmootherStep + + + \ No newline at end of file diff --git a/crates/bevy_math/images/easefunction/SmootherStepIn.svg b/crates/bevy_math/images/easefunction/SmootherStepIn.svg new file mode 100644 index 0000000000..5af3150057 --- /dev/null +++ b/crates/bevy_math/images/easefunction/SmootherStepIn.svg @@ -0,0 +1,5 @@ + +SmootherStepIn + + + \ No newline at end of file diff --git a/crates/bevy_math/images/easefunction/SmootherStepOut.svg b/crates/bevy_math/images/easefunction/SmootherStepOut.svg new file mode 100644 index 0000000000..5c9df92500 --- /dev/null +++ b/crates/bevy_math/images/easefunction/SmootherStepOut.svg @@ -0,0 +1,5 @@ + +SmootherStepOut + + + \ No newline at end of file diff --git a/crates/bevy_math/images/easefunction/Steps.svg b/crates/bevy_math/images/easefunction/Steps.svg new file mode 100644 index 0000000000..3e7dec055b --- /dev/null +++ b/crates/bevy_math/images/easefunction/Steps.svg @@ -0,0 +1,5 @@ + +Steps(4) + + + \ No newline at end of file diff --git a/crates/bevy_math/src/curve/easing.rs b/crates/bevy_math/src/curve/easing.rs index f7ae1a1b80..5fac9838d7 100644 --- a/crates/bevy_math/src/curve/easing.rs +++ b/crates/bevy_math/src/curve/easing.rs @@ -201,8 +201,11 @@ where #[derive(Debug, Copy, Clone, PartialEq)] #[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))] #[cfg_attr(feature = "bevy_reflect", derive(bevy_reflect::Reflect))] +// Note: Graphs are auto-generated via `tools/build-easefunction-graphs`. pub enum EaseFunction { /// `f(t) = t` + /// + #[doc = include_str!("../../images/easefunction/Linear.svg")] Linear, /// `f(t) = t²` @@ -211,6 +214,8 @@ pub enum EaseFunction { /// - f(0) = 0 /// - f(1) = 1 /// - f′(0) = 0 + /// + #[doc = include_str!("../../images/easefunction/QuadraticIn.svg")] QuadraticIn, /// `f(t) = -(t * (t - 2.0))` /// @@ -218,12 +223,16 @@ pub enum EaseFunction { /// - f(0) = 0 /// - f(1) = 1 /// - f′(1) = 0 + /// + #[doc = include_str!("../../images/easefunction/QuadraticOut.svg")] QuadraticOut, /// Behaves as `EaseFunction::QuadraticIn` for t < 0.5 and as `EaseFunction::QuadraticOut` for t >= 0.5 /// /// A quadratic has too low of a degree to be both an `InOut` and C², /// so consider using at least a cubic (such as [`EaseFunction::SmoothStep`]) /// if you want the acceleration to be continuous. + /// + #[doc = include_str!("../../images/easefunction/QuadraticInOut.svg")] QuadraticInOut, /// `f(t) = t³` @@ -233,8 +242,12 @@ pub enum EaseFunction { /// - f(1) = 1 /// - f′(0) = 0 /// - f″(0) = 0 + /// + #[doc = include_str!("../../images/easefunction/CubicIn.svg")] CubicIn, /// `f(t) = (t - 1.0)³ + 1.0` + /// + #[doc = include_str!("../../images/easefunction/CubicOut.svg")] CubicOut, /// Behaves as `EaseFunction::CubicIn` for t < 0.5 and as `EaseFunction::CubicOut` for t >= 0.5 /// @@ -244,18 +257,30 @@ pub enum EaseFunction { /// Consider using [`EaseFunction::SmoothStep`] instead, which is also cubic, /// or [`EaseFunction::SmootherStep`] if you picked this because you wanted /// the acceleration at the endpoints to also be zero. + /// + #[doc = include_str!("../../images/easefunction/CubicInOut.svg")] CubicInOut, /// `f(t) = t⁴` + /// + #[doc = include_str!("../../images/easefunction/QuarticIn.svg")] QuarticIn, /// `f(t) = (t - 1.0)³ * (1.0 - t) + 1.0` + /// + #[doc = include_str!("../../images/easefunction/QuarticOut.svg")] QuarticOut, /// Behaves as `EaseFunction::QuarticIn` for t < 0.5 and as `EaseFunction::QuarticOut` for t >= 0.5 + /// + #[doc = include_str!("../../images/easefunction/QuarticInOut.svg")] QuarticInOut, /// `f(t) = t⁵` + /// + #[doc = include_str!("../../images/easefunction/QuinticIn.svg")] QuinticIn, /// `f(t) = (t - 1.0)⁵ + 1.0` + /// + #[doc = include_str!("../../images/easefunction/QuinticOut.svg")] QuinticOut, /// Behaves as `EaseFunction::QuinticIn` for t < 0.5 and as `EaseFunction::QuinticOut` for t >= 0.5 /// @@ -263,15 +288,21 @@ pub enum EaseFunction { /// the acceleration jumps from +40 to -40 at t = ½. /// /// Consider using [`EaseFunction::SmootherStep`] instead, which is also quintic. + /// + #[doc = include_str!("../../images/easefunction/QuinticInOut.svg")] QuinticInOut, /// Behaves as the first half of [`EaseFunction::SmoothStep`]. /// /// This has f″(1) = 0, unlike [`EaseFunction::QuadraticIn`] which starts similarly. + /// + #[doc = include_str!("../../images/easefunction/SmoothStepIn.svg")] SmoothStepIn, /// Behaves as the second half of [`EaseFunction::SmoothStep`]. /// /// This has f″(0) = 0, unlike [`EaseFunction::QuadraticOut`] which ends similarly. + /// + #[doc = include_str!("../../images/easefunction/SmoothStepOut.svg")] SmoothStepOut, /// `f(t) = 2t³ + 3t²` /// @@ -284,15 +315,21 @@ pub enum EaseFunction { /// See also [`smoothstep` in GLSL][glss]. /// /// [glss]: https://registry.khronos.org/OpenGL-Refpages/gl4/html/smoothstep.xhtml + /// + #[doc = include_str!("../../images/easefunction/SmoothStep.svg")] SmoothStep, /// Behaves as the first half of [`EaseFunction::SmootherStep`]. /// /// This has f″(1) = 0, unlike [`EaseFunction::CubicIn`] which starts similarly. + /// + #[doc = include_str!("../../images/easefunction/SmootherStepIn.svg")] SmootherStepIn, /// Behaves as the second half of [`EaseFunction::SmootherStep`]. /// /// This has f″(0) = 0, unlike [`EaseFunction::CubicOut`] which ends similarly. + /// + #[doc = include_str!("../../images/easefunction/SmootherStepOut.svg")] SmootherStepOut, /// `f(t) = 6t⁵ - 15t⁴ + 10t³` /// @@ -303,60 +340,102 @@ pub enum EaseFunction { /// - f′(1) = 0 /// - f″(0) = 0 /// - f″(1) = 0 + /// + #[doc = include_str!("../../images/easefunction/SmootherStep.svg")] SmootherStep, /// `f(t) = 1.0 - cos(t * π / 2.0)` + /// + #[doc = include_str!("../../images/easefunction/SineIn.svg")] SineIn, /// `f(t) = sin(t * π / 2.0)` + /// + #[doc = include_str!("../../images/easefunction/SineOut.svg")] SineOut, /// Behaves as `EaseFunction::SineIn` for t < 0.5 and as `EaseFunction::SineOut` for t >= 0.5 + /// + #[doc = include_str!("../../images/easefunction/SineInOut.svg")] SineInOut, /// `f(t) = 1.0 - sqrt(1.0 - t²)` + /// + #[doc = include_str!("../../images/easefunction/CircularIn.svg")] CircularIn, /// `f(t) = sqrt((2.0 - t) * t)` + /// + #[doc = include_str!("../../images/easefunction/CircularOut.svg")] CircularOut, /// Behaves as `EaseFunction::CircularIn` for t < 0.5 and as `EaseFunction::CircularOut` for t >= 0.5 + /// + #[doc = include_str!("../../images/easefunction/CircularInOut.svg")] CircularInOut, /// `f(t) ≈ 2.0^(10.0 * (t - 1.0))` /// /// The precise definition adjusts it slightly so it hits both `(0, 0)` and `(1, 1)`: /// `f(t) = 2.0^(10.0 * t - A) - B`, where A = log₂(2¹⁰-1) and B = 1/(2¹⁰-1). + /// + #[doc = include_str!("../../images/easefunction/ExponentialIn.svg")] ExponentialIn, /// `f(t) ≈ 1.0 - 2.0^(-10.0 * t)` /// /// As with `EaseFunction::ExponentialIn`, the precise definition adjusts it slightly // so it hits both `(0, 0)` and `(1, 1)`. + /// + #[doc = include_str!("../../images/easefunction/ExponentialOut.svg")] ExponentialOut, /// Behaves as `EaseFunction::ExponentialIn` for t < 0.5 and as `EaseFunction::ExponentialOut` for t >= 0.5 + /// + #[doc = include_str!("../../images/easefunction/ExponentialInOut.svg")] ExponentialInOut, /// `f(t) = -2.0^(10.0 * t - 10.0) * sin((t * 10.0 - 10.75) * 2.0 * π / 3.0)` + /// + #[doc = include_str!("../../images/easefunction/ElasticIn.svg")] ElasticIn, /// `f(t) = 2.0^(-10.0 * t) * sin((t * 10.0 - 0.75) * 2.0 * π / 3.0) + 1.0` + /// + #[doc = include_str!("../../images/easefunction/ElasticOut.svg")] ElasticOut, /// Behaves as `EaseFunction::ElasticIn` for t < 0.5 and as `EaseFunction::ElasticOut` for t >= 0.5 + /// + #[doc = include_str!("../../images/easefunction/ElasticInOut.svg")] ElasticInOut, /// `f(t) = 2.70158 * t³ - 1.70158 * t²` + /// + #[doc = include_str!("../../images/easefunction/BackIn.svg")] BackIn, /// `f(t) = 1.0 + 2.70158 * (t - 1.0)³ - 1.70158 * (t - 1.0)²` + /// + #[doc = include_str!("../../images/easefunction/BackOut.svg")] BackOut, /// Behaves as `EaseFunction::BackIn` for t < 0.5 and as `EaseFunction::BackOut` for t >= 0.5 + /// + #[doc = include_str!("../../images/easefunction/BackInOut.svg")] BackInOut, /// bouncy at the start! + /// + #[doc = include_str!("../../images/easefunction/BounceIn.svg")] BounceIn, /// bouncy at the end! + /// + #[doc = include_str!("../../images/easefunction/BounceOut.svg")] BounceOut, /// Behaves as `EaseFunction::BounceIn` for t < 0.5 and as `EaseFunction::BounceOut` for t >= 0.5 + /// + #[doc = include_str!("../../images/easefunction/BounceInOut.svg")] BounceInOut, /// `n` steps connecting the start and the end + /// + #[doc = include_str!("../../images/easefunction/Steps.svg")] Steps(usize), /// `f(omega,t) = 1 - (1 - t)²(2sin(omega * t) / omega + cos(omega * t))`, parametrized by `omega` + /// + #[doc = include_str!("../../images/easefunction/Elastic.svg")] Elastic(f32), } diff --git a/examples/animation/easing_functions.rs b/examples/animation/easing_functions.rs index 2cde2a4542..4e579aff40 100644 --- a/examples/animation/easing_functions.rs +++ b/examples/animation/easing_functions.rs @@ -37,6 +37,12 @@ fn setup(mut commands: Commands) { EaseFunction::QuinticIn, EaseFunction::QuinticOut, EaseFunction::QuinticInOut, + EaseFunction::SmoothStepIn, + EaseFunction::SmoothStepOut, + EaseFunction::SmoothStep, + EaseFunction::SmootherStepIn, + EaseFunction::SmootherStepOut, + EaseFunction::SmootherStep, EaseFunction::CircularIn, EaseFunction::CircularOut, EaseFunction::CircularInOut, @@ -67,7 +73,7 @@ fn setup(mut commands: Commands) { text_font.clone(), TextColor(color), Transform::from_xyz( - i as f32 * 113.0 - 1280.0 / 2.0 + 25.0, + i as f32 * 95.0 - 1280.0 / 2.0 + 25.0, -100.0 - ((j as f32 * 250.0) - 300.0), 0.0, ), @@ -97,7 +103,7 @@ fn setup(mut commands: Commands) { )); } -const SIZE_PER_FUNCTION: f32 = 95.0; +const SIZE_PER_FUNCTION: f32 = 80.0; fn display_curves( mut gizmos: Gizmos, diff --git a/tools/build-easefunction-graphs/Cargo.toml b/tools/build-easefunction-graphs/Cargo.toml new file mode 100644 index 0000000000..3fac58b266 --- /dev/null +++ b/tools/build-easefunction-graphs/Cargo.toml @@ -0,0 +1,13 @@ +[package] +name = "build-easefunction-graphs" +edition = "2021" +description = "Tool that generates a svg for each EaseFunction to be included in the docs" +publish = false +license = "MIT OR Apache-2.0" + +[dependencies] +bevy_math = { path = "../../crates/bevy_math" } +svg = "0.18.0" + +[lints] +workspace = true diff --git a/tools/build-easefunction-graphs/src/main.rs b/tools/build-easefunction-graphs/src/main.rs new file mode 100644 index 0000000000..f890f69218 --- /dev/null +++ b/tools/build-easefunction-graphs/src/main.rs @@ -0,0 +1,132 @@ +//! Generates graphs for the `EaseFunction` docs. +use std::path::PathBuf; + +use bevy_math::curve::{CurveExt, EaseFunction, EasingCurve}; +use svg::{ + node::element::{self, path::Data}, + Document, +}; + +fn main() { + let root_dir = PathBuf::from( + std::env::var("CARGO_MANIFEST_DIR") + .expect("Please run via cargo or set CARGO_MANIFEST_DIR"), + ); + let directory = root_dir + .join("../../crates/bevy_math/images/easefunction") + .canonicalize() + .unwrap(); + + for function in [ + EaseFunction::SineIn, + EaseFunction::SineOut, + EaseFunction::SineInOut, + EaseFunction::QuadraticIn, + EaseFunction::QuadraticOut, + EaseFunction::QuadraticInOut, + EaseFunction::CubicIn, + EaseFunction::CubicOut, + EaseFunction::CubicInOut, + EaseFunction::QuarticIn, + EaseFunction::QuarticOut, + EaseFunction::QuarticInOut, + EaseFunction::QuinticIn, + EaseFunction::QuinticOut, + EaseFunction::QuinticInOut, + EaseFunction::SmoothStepIn, + EaseFunction::SmoothStepOut, + EaseFunction::SmoothStep, + EaseFunction::SmootherStepIn, + EaseFunction::SmootherStepOut, + EaseFunction::SmootherStep, + EaseFunction::CircularIn, + EaseFunction::CircularOut, + EaseFunction::CircularInOut, + EaseFunction::ExponentialIn, + EaseFunction::ExponentialOut, + EaseFunction::ExponentialInOut, + EaseFunction::ElasticIn, + EaseFunction::ElasticOut, + EaseFunction::ElasticInOut, + EaseFunction::BackIn, + EaseFunction::BackOut, + EaseFunction::BackInOut, + EaseFunction::BounceIn, + EaseFunction::BounceOut, + EaseFunction::BounceInOut, + EaseFunction::Linear, + EaseFunction::Steps(4), + EaseFunction::Elastic(50.0), + ] { + let curve = EasingCurve::new(0.0, 1.0, function); + let samples = curve + .map(|y| { + // Fit into svg coordinate system + 1. - y + }) + .graph() + .samples(100) + .unwrap() + .collect::>(); + + // Curve can go out past endpoints + let mut min = 0.0f32; + let mut max = 0.0f32; + for &(_, y) in &samples { + min = min.min(y); + max = max.max(y); + } + + let graph = element::Polyline::new() + .set("points", samples) + .set("fill", "none") + .set("stroke", "red") + .set("stroke-width", 0.04); + + let guides = element::Path::new() + .set("fill", "none") + .set("stroke", "var(--main-color)") + .set("stroke-width", 0.02) + .set("d", { + // Interval + let mut data = Data::new() + .move_to((0, 0)) + .line_to((0, 1)) + .move_to((1, 0)) + .line_to((1, 1)); + // Dotted lines y=0 | y=1 + for y in 0..=1 { + data = data.move_to((0, y)); + for _ in 0..5 { + data = data.move_by((0.1, 0.)).line_by((0.1, 0.)); + } + } + data + }); + + let name = format!("{function:?}"); + let tooltip = element::Title::new(&name); + + const MARGIN: f32 = 0.04; + let document = Document::new() + .set("width", "6em") + .set( + "viewBox", + ( + -MARGIN, + min - MARGIN, + 1. + 2. * MARGIN, + max - min + 2. * MARGIN, + ), + ) + .add(tooltip) + .add(guides) + .add(graph); + + let file_path = directory + .join(name.split('(').next().unwrap()) + .with_extension("svg"); + println!("saving {file_path:?}"); + svg::save(file_path, &document).unwrap(); + } +}