# Speed Lines

A burst of animated radial speed lines around a subject.

Element page: [https://www.remotion.dev/elements/storytelling/speed-lines/](https://www.remotion.dev/elements/storytelling/speed-lines/)

## Installation

Install this Element into a composition of your Remotion project:

```sh
npx remotion elements use https://www.remotion.dev/elements/storytelling/speed-lines/ --composition <composition-id> --yes
```

Replace `<composition-id>` with the ID of the composition to add the Element to. The command installs the dependencies, downloads the assets, writes the source file and adds the Element to the composition. See [`npx remotion elements use`](https://www.remotion.dev/docs/cli/elements/use.md).

## Manual installation

To install the Element manually instead, save the source below as `speed-lines.element.tsx` in your Remotion project and import its exported component.

## Source

```tsx
import React from 'react';
import {
	AbsoluteFill,
	Interactive,
	interpolate,
	random,
	useCurrentFrame,
	useVideoConfig,
	type InteractivitySchema,
} from 'remotion';

type SpeedLinesProps = {
	readonly color?: string;
};

const SpeedLinesInner: React.FC<SpeedLinesProps> = ({color = '#ffffff'}) => {
	const frame = useCurrentFrame();
	const {width, height, durationInFrames} = useVideoConfig();
	const seed = Math.floor(frame / 2);
	const cx = width / 2;
	const cy = height / 2;
	const far = Math.hypot(width, height);
	const lines = new Array(56).fill(true).map((_, i) => {
		const angle = (i / 56) * Math.PI * 2 + random(`angle-${i}-${seed}`) * 0.08;
		const spread = 0.006 + random(`spread-${i}-${seed}`) * 0.014;
		const inner = 0.36 + random(`inner-${i}-${seed}`) * 0.22;
		const x1 = cx + Math.cos(angle - spread) * far;
		const y1 = cy + Math.sin(angle - spread) * far;
		const x2 = cx + Math.cos(angle + spread) * far;
		const y2 = cy + Math.sin(angle + spread) * far;
		const xi = cx + Math.cos(angle) * inner * (width / 2);
		const yi = cy + Math.sin(angle) * inner * (height / 2);
		return `M ${xi} ${yi} L ${x1} ${y1} L ${x2} ${y2} Z`;
	});

	return (
		<AbsoluteFill
			name="Speed lines fade"
			style={{
				opacity: interpolate(
					frame,
					[0, 3, durationInFrames - 5, durationInFrames - 1],
					[0, 0.85, 0.85, 0],
					{extrapolateLeft: 'clamp', extrapolateRight: 'clamp'},
				),
			}}
		>
			<svg width={width} height={height} viewBox={`0 0 ${width} ${height}`}>
				{lines.map((d, i) => (
					<path key={i} d={d} fill={color} />
				))}
			</svg>
		</AbsoluteFill>
	);
};

const speedLinesSchema = {
	color: {type: 'color', default: '#ffffff', description: 'Color'},
} as const satisfies InteractivitySchema;

export const SpeedLines = Interactive.create({
	Component: SpeedLinesInner,
	schema: speedLinesSchema,
	layout: 'absolute-fill',
});
```

