Skip to content

🎥 Make videos programmatically with React

Document easingf

Jonny Burgerd2c706976eb1
diff --git a/packages/docs/docs/easing.md b/packages/docs/docs/easing.md
new file mode 100644
index 0000000000..7c2792b4fe
--- /dev/null
+++ b/packages/docs/docs/easing.md
@@ -0,0 +1,265 @@
+---
+id: easing
+title: Easing
+---
+
+:::info
+The Easing API is the exact same as the one from [React Native](https://reactnative.dev/docs/easing) and the documentation has been copied over. Credit goes to them for this excellent API.
+:::
+
+The `Easing` module implements common easing functions. You can use it with the [`interpolate()`](interpolate) API.
+
+You can find a visualization of some common easing functions at http://easings.net/
+
+### Predefined animations
+
+The `Easing` module provides several predefined animations through the following methods:
+
+- [`back`](easing#back) provides a basic animation where the object goes slightly back before moving forward
+- [`bounce`](easing#bounce) provides a bouncing animation
+- [`ease`](easing#ease) provides a basic inertial animation
+- [`elastic`](easing#elastic) provides a basic spring interaction
+
+### Standard functions
+
+Three standard easing functions are provided:
+
+- [`linear`](easing#linear)
+- [`quad`](easing#quad)
+- [`cubic`](easing#cubic)
+
+The [`poly`](easing#poly) function can be used to implement quartic, quintic, and other higher power functions.
+
+### Additional functions
+
+Additional mathematical functions are provided by the following methods:
+
+- [`bezier`](easing#bezier) provides a cubic bezier curve
+- [`circle`](easing#circle) provides a circular function
+- [`sin`](easing#sin) provides a sinusoidal function
+- [`exp`](easing#exp) provides an exponential function
+
+The following helpers are used to modify other easing functions.
+
+- [`in`](easing#in) runs an easing function forwards
+- [`inOut`](easing#inout) makes any easing function symmetrical
+- [`out`](easing#out) runs an easing function backwards
+
+## Example
+
+```tsx
+import {interpolate, Easing} from 'remotion';
+
+const MyVideo: React.FC = () => {
+ const frame = useCurrentFrame();
+ const interpolated = interpolate(frame, [0, 100], {
+ easing: Easing.bezier(0.8, 0.22, 0.96, 0.65),
+ extrapolateLeft: 'clamp',
+ extrapolateRight: 'clamp',
+ });
+
+ return (
+ <AbsoluteFill style={{transform: `scale(${interpolated})`, backgroundColor: 'red'}} />
+ )
+}
+```
+
+---
+
+# Reference
+
+## Methods
+
+### `step0()`
+
+```jsx
+static step0(n)
+```
+
+A stepping function, returns 1 for any positive value of `n`.
+
+---
+
+### `step1()`
+
+```jsx
+static step1(n)
+```
+
+A stepping function, returns 1 if `n` is greater than or equal to 1.
+
+---
+
+### `linear()`
+
+```jsx
+static linear(t)
+```
+
+A linear function, `f(t) = t`. Position correlates to elapsed time one to one.
+
+http://cubic-bezier.com/#0,0,1,1
+
+---
+
+### `ease()`
+
+```jsx
+static ease(t)
+```
+
+A basic inertial interaction, similar to an object slowly accelerating to speed.
+
+http://cubic-bezier.com/#.42,0,1,1
+
+---
+
+### `quad()`
+
+```jsx
+static quad(t)
+```
+
+A quadratic function, `f(t) = t * t`. Position equals the square of elapsed time.
+
+http://easings.net/#easeInQuad
+
+---
+
+### `cubic()`
+
+```jsx
+static cubic(t)
+```
+
+A cubic function, `f(t) = t * t * t`. Position equals the cube of elapsed time.
+
+http://easings.net/#easeInCubic
+
+---
+
+### `poly()`
+
+```jsx
+static poly(n)
+```
+
+A power function. Position is equal to the Nth power of elapsed time.
+
+n = 4: http://easings.net/#easeInQuart n = 5: http://easings.net/#easeInQuint
+
+---
+
+### `sin()`
+
+```jsx
+static sin(t)
+```
+
+A sinusoidal function.
+
+http://easings.net/#easeInSine
+
+---
+
+### `circle()`
+
+```jsx
+static circle(t)
+```
+
+A circular function.
+
+http://easings.net/#easeInCirc
+
+---
+
+### `exp()`
+
+```jsx
+static exp(t)
+```
+
+An exponential function.
+
+http://easings.net/#easeInExpo
+
+---
+
+### `elastic()`
+
+```jsx
+static elastic(bounciness)
+```
+
+A basic elastic interaction, similar to a spring oscillating back and forth.
+
+Default bounciness is 1, which overshoots a little bit once. 0 bounciness doesn't overshoot at all, and bounciness of N > 1 will overshoot about N times.
+
+http://easings.net/#easeInElastic
+
+---
+
+### `back()`
+
+```jsx
+static back(s)
+```
+
+Use with `Animated.parallel()` to create a basic effect where the object animates back slightly as the animation starts.
+
+---
+
+### `bounce()`
+
+```jsx
+static bounce(t)
+```
+
+Provides a basic bouncing effect.
+
+http://easings.net/#easeInBounce
+
+---
+
+### `bezier()`
+
+```jsx
+static bezier(x1, y1, x2, y2)
+```
+
+Provides a cubic bezier curve, equivalent to CSS Transitions' `transition-timing-function`.
+
+A useful tool to visualize cubic bezier curves can be found at http://cubic-bezier.com/
+
+---
+
+### `in()`
+
+<!-- prettier-ignore-start -->
+```jsx
+static in(easing);
+```
+<!-- prettier-ignore-end -->
+
+Runs an easing function forwards.
+
+---
+
+### `out()`
+
+```jsx
+static out(easing)
+```
+
+Runs an easing function backwards.
+
+---
+
+### `inOut()`
+
+```jsx
+static inOut(easing)
+```
+
+Makes any easing function symmetrical. The easing function will run forwards for half of the duration, then backwards for the rest of the duration.
diff --git a/packages/docs/docs/interpolate.md b/packages/docs/docs/interpolate.md
index e909094c99..6ea17a2ada 100644
--- a/packages/docs/docs/interpolate.md
+++ b/packages/docs/docs/interpolate.md
@@ -52,4 +52,19 @@ interpolate(1.5, [0, 1], [0, 2], {extrapolateRight: 'identity'}) // 1.5
_Default_: `(x) => x`
Function which allows you to customize the input, for example to apply a certain easing function.
-By default, the input is left unmodified, resulting in a pure linear interpolation.
+By default, the input is left unmodified, resulting in a pure linear interpolation. [Read the documentation for the built-in easing functions](easing).
+
+```tsx
+import {interpolate, Easing} from 'remotion';
+
+interpolate(frame, [0, 100], {
+ easing: Easing.bezier(0.8, 0.22, 0.96, 0.65),
+ extrapolateLeft: 'clamp',
+ extrapolateRight: 'clamp',
+})
+```
+
+## See also
+
+- [Easing](easing)
+- [spring()](spring)
diff --git a/packages/docs/docs/spring.md b/packages/docs/docs/spring.md
index 227504f713..28936dd44e 100644
--- a/packages/docs/docs/spring.md
+++ b/packages/docs/docs/spring.md
@@ -77,3 +77,7 @@ Watch: **[The perfect spring animation](https://www.youtube.com/watch?v=GE8ZqrKq
## Credit
This function was taken from [Reanimated 2](https://github.com/software-mansion/react-native-reanimated), which in itself was a huge inspiration for Remotion.
+
+## See also
+
+- [interpolate](interpolate)
diff --git a/packages/docs/sidebars.js b/packages/docs/sidebars.js
index ae7cda4dee..0502c43cab 100644
--- a/packages/docs/sidebars.js
+++ b/packages/docs/sidebars.js
@@ -45,6 +45,7 @@ module.exports = {
"absolute-fill",
"img",
"iframe",
+ "easing",
],
},
"license",