🎥 Make videos programmatically with React
Update interpolate.md
Jonny Burger9d2344a3c4e8
diff --git a/packages/docs/docs/interpolate.md b/packages/docs/docs/interpolate.mdindex 26634fc9e8..892219d422 100644--- a/packages/docs/docs/interpolate.md+++ b/packages/docs/docs/interpolate.md@@ -3,36 +3,107 @@ title: interpolate()id: interpolate----Allows you to map a value to another using a concise syntax.+Allows you to map a range of values to another using a concise syntax.-`interpolate()` now supports number array (array length >= 2) in input and outpur range. Make sure the length or input and output array length is same.+## Example: Fade-in effect-:::warning-This component is part of Remotion 2.0 which is not yet released. The information on this page might not yet accurately reflect the current state of Remotions API.-:::warning+In this example, we are fading in some content by calculating the opacity for a certain point of time.+At frame 0 (the start of the video), we want the opacity to be 0.+At frame 20, we want the opacity to be 1.-## Example+Using the following snippet, we can calculate the current opacity for any frame:```tsximport {useCurrentFrame, interpolate} from 'remotion'-const frame = useCurrentFrame() // 10-const opacity = interpolate(input, [0, 20], [0, 1]) // 0.5+const frame = useCurrentFrame(); // 10+const opacity = interpolate(input,+ [0, 20],+ [0, 1]+); // 0.5+```-//this is Remotion2.0 feature-const opacity = interpolate(input, [0, 10, 20], [0, 0.7, 1]) //0.7+## Example: Fade in and out++We keep our fade in effect but add a fade out effect at the end.+20 frames before the video ends, the opacity should still be 1.+At the end, the opacity should be 0.++We can interpolate over multiple points in one go and use [`useVideoConfig()`](/docs/use-video-config) to determine the duration of the composition.++```tsx+import {useCurrentFrame, interpolate} from 'remotion'++const frame = useCurrentFrame();+const {durationInFrames} = useVideoConfig();+const opacity = interpolate(+ input,+ [0, 20, durationInFrames - 20, durationInFrames],+// v--v---v----------------------v+ [0, 1, 1, 0]+)+```++## Example: interpolate a spring animation++We don't necessarily have to interpolate over time - we can use any value to drive an animation.+Let's assume we want to animate an object on the X axis from 0 to 200 pixels and use a spring animation for it.++Let's create a spring:++```tsx+import {useCurrentFrame, interpolate, spring} from 'remotion';++const frame = useCurrentFrame();+const {fps} = useVideoConfig();+const driver = spring({+ frame,+ fps+});+```++A [`spring()`](/docs/spring) animation will always animate from 0 to 1.+Given that knowledge, we can interpolate the spring value to go from 0 to 200.++```tsx+const marginLeft = interpolate(driver, [0, 1], [0, 200])+```++We can then apply it to an HTML element.++```tsx+<div style={{marginLeft}}></div>+```++## Example: Prevent the output from going outside the output range++Consider the following interpolation which is supposed to animate the scale over 20 frames:++```tsx+const scale = interpolate(frame, [0, 20], [0, 1])+```++This works, but after 20 frames, the value keeps growing. For example, at frame 40, the scale will be `2`.+To prevent this, this we can use the `extrapolateLeft` and `extrapolateRight` options and set them to `'clamp'` to prevent the result going outside the output range.++```tsx+const scale = interpolate(frame, [0, 20], [0, 1], {+ extrapolateRight: 'clamp'+});```-## Params+## Reference++### Params1. The input value.2. The range of values that you expect the input to assume.3. The range of output values that you want the input to map to.4. Options object.-## Options+### Options-### extrapolateLeft+#### extrapolateLeft_Default_: `extend`@@ -42,7 +113,7 @@ What should happen if the input value is outside left the input range:- `clamp`: Return the closest value inside the range instead- `identity`: Return the input value instead.-### extrapolateRight+#### extrapolateRight_Default_: `extend`@@ -56,7 +127,7 @@ interpolate(1.5, [0, 1], [0, 2], {extrapolateRight: 'clamp'}) // 2interpolate(1.5, [0, 1], [0, 2], {extrapolateRight: 'identity'}) // 1.5```-### easing+#### easing_Default_: `(x) => x`