Slot Machine Roll
Vertical reel scrolls characters from one value to another.
Source
components/kuchi/slot-machine-roll.tsx
1"use client";23import { spring, useCurrentFrame, useVideoConfig } from "remotion";45export interface SlotMachineRollProps {6 from?: string;7 to?: string;8 fontSize?: number;9 color?: string;10 fontWeight?: number;11 speed?: number;12 className?: string;13}1415export function SlotMachineRoll({16 from = "$99",17 to = "$199",18 fontSize = 120,19 color = "#171717",20 fontWeight = 700,21 speed = 1,22 className,23}: SlotMachineRollProps) {24 const frame = useCurrentFrame() * speed;25 const { fps } = useVideoConfig();2627 const len = Math.max(from.length, to.length);28 const paddedFrom = from.padStart(len, " ");29 const paddedTo = to.padStart(len, " ");3031 const columns = [];32 for (let i = 0; i < len; i++) {33 const raw = spring({34 frame: frame - i * 4,35 fps,36 config: { damping: 14 },37 });38 const t = Math.max(0, Math.min(1, raw));39 columns.push(40 <span41 key={i}42 style={{43 display: "inline-block",44 overflow: "hidden",45 height: "1.1em",46 lineHeight: "1.1em",47 verticalAlign: "top",48 width: "0.7em",49 textAlign: "center",50 }}51 >52 <span53 style={{54 display: "flex",55 flexDirection: "column",56 translate: `0 ${-t * fontSize * 1.1}px`,57 }}58 >59 <span>{paddedFrom[i]}</span>60 <span>{paddedTo[i]}</span>61 </span>62 </span>,63 );64 }6566 return (67 <div68 style={{69 position: "absolute",70 inset: 0,71 display: "flex",72 alignItems: "center",73 justifyContent: "center",74 background: "white",75 }}76 >77 <span78 className={className}79 style={{80 fontSize,81 fontWeight,82 color,83 letterSpacing: "-0.03em",84 fontFamily:85 "var(--font-geist-sans), -apple-system, BlinkMacSystemFont, sans-serif",86 lineHeight: 1.1,87 }}88 >89 {columns}90 </span>91 </div>92 );93}









