Hook Punch
A two-beat hook stops the scroll, then a gradient payoff lands: 'This video took 1 day.'.
Source
components/kuchi/hook-punch.tsx
1"use client";23import { loadFont } from "@remotion/google-fonts/BricolageGrotesque";4import { loadFont as loadSerif } from "@remotion/google-fonts/InstrumentSerif";5import type React from "react";6import {7 AbsoluteFill,8 Easing,9 interpolate,10 spring,11 useCurrentFrame,12 useVideoConfig,13} from "remotion";14import type { GradientParams } from "@/lib/kuchi/gsh/gradient-engine";15import { GshGround } from "@/lib/kuchi/gsh/gsh-ground";16import type { GshPresetId } from "@/lib/kuchi/gsh/presets";1718const { fontFamily: grotesk } = loadFont("normal", {19 weights: ["300", "400"],20 subsets: ["latin"],21});22const { fontFamily: serifItalic } = loadSerif("italic", {23 weights: ["400"],24 subsets: ["latin"],25});2627export interface HookPunchProps {28 /** First beat, set in the grotesk. */29 stop?: string;30 /** Second word of the first beat, set in the serif italic. */31 scroll?: string;32 /** Lead-in of the second beat. */33 lead?: string;34 /** The payoff, slammed huge. */35 payoff?: string;36 /** Kept for the shared draft API; the colour comes from the ground. */37 accent?: string;38 /** Text color; overrides the theme ink. */39 ink?: string;40 /** Solid fill in place of the gradient ground; "transparent" drops it. */41 background?: string;42 /** Typeface for the grotesk words. Load it yourself; Bricolage Grotesque by default. */43 fontFamily?: string;44 /** Frames the first beat holds before the whip to the payoff. */45 hold?: number;46 /** Size of the words, around the frame's center. */47 scale?: number;48 /** Frames to hold the first frame before anything moves. */49 delay?: number;50 theme?: "dark" | "light";51 /** gradients.sh preset id for the ground. */52 ground?: GshPresetId;53 /** Overrides for the ground shader. */54 groundParams?: Partial<GradientParams>;55 speed?: number;56}5758const BEATS = {59 stop: 0,60 scroll: 6,61 whip: 30,62 whipLen: 8,63 lead: 33,64 pay: 42,65 rise: 43,66} as const;6768const EXIT = Easing.bezier(0.55, 0, 1, 0.45);69const LIGHT = Easing.bezier(0.22, 1, 0.36, 1);70const CAMERA = Easing.bezier(0.87, 0, 0.13, 1);71const HEAVY = { mass: 1, damping: 26, stiffness: 120 };72const CARD = { mass: 0.8, damping: 18, stiffness: 160 };73const CLAMP = {74 extrapolateLeft: "clamp",75 extrapolateRight: "clamp",76} as const;7778const THEMES = {79 dark: {80 stage: "#03040A",81 ink: "#F2F3F8",82 preset: "cobalt-rise" as GshPresetId,83 params: undefined as Partial<GradientParams> | undefined,84 veilFrom: 0.86,85 veilTo: 0.34,86 },87 light: {88 stage: "#EEF0F6",89 ink: "#0E1230",90 preset: "paper-crease" as GshPresetId,91 params: undefined as Partial<GradientParams> | undefined,92 veilFrom: 0.8,93 veilTo: 0.22,94 },95} as const;9697function ramp(t: number, from: number, len: number) {98 return interpolate(t, [from, from + len], [0, 1], CLAMP);99}100101function kick(d: number) {102 if (d < 0) return 0;103 if (d < 2) return d / 2;104 const k = Math.max(0, 1 - (d - 2) / 8);105 return k * k;106}107108function shake(d: number, amp: number, seed: number) {109 if (d < 0 || d > 7) return { x: 0, y: 0 };110 const k = (1 - d / 7) ** 2;111 return {112 x: amp * k * Math.sin(d * 2.7 + seed),113 y: amp * 0.7 * k * Math.cos(d * 3.3 + seed * 1.7),114 };115}116117/** The foreground at `scale`, around the frame's center; nothing extra at 1. */118function ScaleLayer({119 scale,120 children,121}: {122 scale: number;123 children: React.ReactNode;124}) {125 if (scale === 1) return children;126 return (127 <AbsoluteFill style={{ transform: `scale(${scale})` }}>128 {children}129 </AbsoluteFill>130 );131}132133export function HookPunch({134 stop = "Stop",135 scroll = "scrolling.",136 lead = "This video took",137 payoff = "1 day.",138 ink,139 background,140 fontFamily = grotesk,141 hold = BEATS.whip,142 scale = 1,143 delay = 0,144 theme = "dark",145 ground,146 groundParams,147 speed = 1,148}: HookPunchProps) {149 const t = Math.max(0, useCurrentFrame() - delay) * speed;150 const { width: W, height: H, fps } = useVideoConfig();151 const c = THEMES[theme];152 const stage =153 background === undefined154 ? c.stage155 : background === "transparent"156 ? "transparent"157 : background;158 const shift = hold - BEATS.whip;159 const beats = {160 ...BEATS,161 whip: BEATS.whip + shift,162 lead: BEATS.lead + shift,163 pay: BEATS.pay + shift,164 rise: BEATS.rise + shift,165 };166 const tall = H > W;167 const base = tall ? W * 0.56 : H;168 const u = Math.min(W / 1280, H / 720);169170 const slam = (at: number, from: number) => {171 const p = spring({ frame: t - at, fps, config: CARD });172 return {173 scale: from + (1 - from) * p,174 blur: Math.max(0, 1 - p) ** 2 * 18,175 opacity: ramp(t, at - 1, 2),176 };177 };178179 const bump = Math.max(180 kick(t - beats.stop - 4),181 kick(t - beats.scroll - 4),182 1.3 * kick(t - beats.pay - 4),183 );184 const s1 = shake(t - beats.stop - 4, 6 * u, 0.4);185 const s2 = shake(t - beats.scroll - 4, 5 * u, 2.1);186 const s3 = shake(t - beats.pay - 4, 8 * u, 4.2);187 const camScale = 1 + 0.03 * bump;188189 const pStop = slam(beats.stop, 1.5);190 const pScroll = slam(beats.scroll, 1.5);191 const shove = 1 - spring({ frame: t - beats.scroll, fps, config: HEAVY });192 const creep1 = interpolate(t, [beats.scroll + 6, beats.whip], [1, 1.04], {193 ...CLAMP,194 easing: CAMERA,195 });196 const whip = EXIT(ramp(t, beats.whip, beats.whipLen));197 const line1Scale = creep1 * (1 + 1.6 * whip);198 const line1Blur = 22 * whip;199 const line1Opacity = 1 - ramp(t, beats.whip + 3, beats.whipLen - 3);200201 const lead2 = spring({ frame: t - beats.lead, fps, config: HEAVY });202 const leadScale = 0.6 + 0.4 * lead2;203 const leadBlur = Math.max(0, 1 - lead2) * 16;204 const leadOpacity = ramp(t, beats.lead, 3);205 const pPay = slam(beats.pay, 1.6);206 const creep2 = interpolate(t, [beats.pay + 6, beats.pay + 62], [1, 1.035], {207 ...CLAMP,208 easing: CAMERA,209 });210211 const rise = LIGHT(ramp(t, beats.rise, 26));212 const veil = c.veilFrom + (c.veilTo - c.veilFrom) * rise;213 const groundShift = (0.06 + (1 - rise) * 0.14) * H;214215 const bigFs = 0.43 * base;216 const leadFs = 0.11 * base;217 const payFs = 0.56 * base;218219 const word = (220 text: string,221 family: string,222 fs: number,223 p: { scale: number; blur: number; opacity: number },224 extra: React.CSSProperties = {},225 ) => (226 <div227 style={{228 fontFamily: family,229 fontSize: fs,230 lineHeight: 0.86,231 whiteSpace: "nowrap",232 transform: `scale(${p.scale})`,233 filter: p.blur > 0.2 ? `blur(${p.blur * u}px)` : undefined,234 opacity: p.opacity,235 ...extra,236 }}237 >238 {text}239 </div>240 );241242 return (243 <AbsoluteFill style={{ background: stage, overflow: "hidden" }}>244 {background === undefined ? (245 <>246 <AbsoluteFill247 style={{248 top: -0.3 * H,249 height: 1.55 * H,250 transform: `translateY(${groundShift - 0.25 * H}px) scale(1.06)`,251 }}252 >253 <GshGround254 preset={ground ?? c.preset}255 params={groundParams ?? c.params}256 timeOffset={3}257 timeScale={0.5}258 />259 </AbsoluteFill>260 <AbsoluteFill style={{ background: c.stage, opacity: veil }} />261 </>262 ) : null}263264 <ScaleLayer scale={scale}>265 <div266 style={{267 position: "absolute",268 inset: 0,269 transform: `translate(${s1.x + s2.x + s3.x}px, ${s1.y + s2.y + s3.y}px) scale(${camScale})`,270 transformOrigin: "50% 50%",271 color: ink ?? c.ink,272 }}273 >274 {t < beats.whip + beats.whipLen ? (275 <div276 style={{277 position: "absolute",278 inset: 0,279 display: "flex",280 flexDirection: "column",281 alignItems: "center",282 justifyContent: "center",283 gap: 0.01 * base,284 transform: `scale(${line1Scale})`,285 filter:286 line1Blur > 0.2 ? `blur(${line1Blur * u}px)` : undefined,287 opacity: line1Opacity,288 }}289 >290 <div291 style={{292 transform: `translateY(${shove * 0.5 * (bigFs * 1.06 * 0.86 + 0.01 * base)}px)`,293 }}294 >295 {word(stop, fontFamily, bigFs, pStop, {296 fontWeight: 400,297 letterSpacing: "-0.05em",298 paddingRight: 0.02 * W,299 })}300 </div>301 {word(scroll, serifItalic, bigFs * 1.06, pScroll, {302 fontStyle: "italic",303 fontWeight: 400,304 letterSpacing: "-0.03em",305 paddingLeft: (tall ? 0.03 : 0.06) * W,306 })}307 </div>308 ) : null}309310 {t >= beats.lead ? (311 <div312 style={{313 position: "absolute",314 inset: 0,315 display: "flex",316 flexDirection: "column",317 alignItems: "center",318 justifyContent: "center",319 transform: `scale(${creep2})`,320 }}321 >322 <div323 style={{324 fontFamily,325 fontWeight: 300,326 fontSize: leadFs,327 lineHeight: 1,328 letterSpacing: "-0.03em",329 whiteSpace: "nowrap",330 transform: `scale(${leadScale})`,331 filter:332 leadBlur > 0.2 ? `blur(${leadBlur * u}px)` : undefined,333 opacity: leadOpacity,334 marginBottom: 0.02 * base,335 }}336 >337 {lead}338 </div>339 <div style={{ height: payFs * 0.92 }}>340 {t >= beats.pay - 1341 ? word(payoff, fontFamily, payFs, pPay, {342 fontWeight: 400,343 lineHeight: 1,344 letterSpacing: "-0.055em",345 paddingRight: 0.03 * payFs,346 })347 : null}348 </div>349 </div>350 ) : null}351 </div>352 </ScaleLayer>353 </AbsoluteFill>354 );355}









