Crumple Toss
remocn/crumple-tossFreeComponent
Crushes an element into a ball of paper and throws it out of frame on an arc, leaving the scene around it running.
Install it
npx shadcn@latest add https://www.remocn.dev/r/crumple-toss.jsonSource
1"use client";23import type React from "react";4import { useCurrentFrame } from "remotion";5import { DEFAULT_STEP, hashRange, qstep } from "@/lib/remocn/stop-motion";67const GRAVITY = 0.9;8const FLIGHT_SHRINK = 0.5;9const EXIT_OPACITY = 0.4;1011const FOLD_TILT = 46;12const WAD_REACH = 0.27;13const WAD_SPREAD = 0.07;14const ANGLE_JITTER = 0.22;15const SCALE_SPREAD = 0.25;16const DEFAULT_RANDOMNESS = 0.6;17const DEFAULT_LAYERS = 2;18const LAYER_TILT_FLOOR = 0.45;19const FACET_SIZE = 0.5;20const FACET_CAP = 0.5;2122const TONE_PATTERN = [0, 1, 3, 1, 0, 2, 1, 2, 0];2324const TONES = [25 { lit: "rgba(255,255,255,0.66)", dark: "rgba(255,255,255,0.18)" },26 { lit: "rgba(255,255,255,0.30)", dark: "rgba(38,36,44,0.10)" },27 { lit: "rgba(255,255,255,0.08)", dark: "rgba(38,36,44,0.20)" },28 { lit: "rgba(38,36,44,0.06)", dark: "rgba(38,36,44,0.30)" },29];3031const LIGHT_ANGLE = -55;32const CREASE_BLEND = 9;3334export type CrumplePhase = "idle" | "crumple" | "toss" | "gone";3536export type CrumplePose = {37 phase: CrumplePhase;38 crush: number;39 scale: number;40 rotate: number;41 x: number;42 y: number;43 opacity: number;44};4546export type CrumpleSegment = {47 clip: [number, number][];48 origin: [number, number];49 dx: number;50 dy: number;51 scale: number;52 rotate: number;53 tone: number;54 crease: number;55};5657export type CrumpleTossTiming = {58 at: number;59 crumpleSteps?: number;60 tossSteps?: number;61 direction?: number;62 distance?: number;63 spin?: number;64 crushTo?: number;65 seed?: string;66 step?: number;67};6869const rayToEdge = (70 angle: number,71 halfWidth: number,72 halfHeight: number,73): [number, number] => {74 const cos = Math.cos(angle);75 const sin = Math.sin(angle);76 const t = Math.min(77 halfWidth / (Math.abs(cos) || 1e-9),78 halfHeight / (Math.abs(sin) || 1e-9),79 );80 return [cos * t, sin * t];81};8283const normalize = (angle: number) => {84 const turn = Math.PI * 2;85 return ((angle % turn) + turn) % turn;86};8788const shrinkToward = (89 [x, y]: [number, number],90 factor: number,91): [number, number] => [x * factor, y * factor];9293const averageOf = (points: [number, number][]): [number, number] => [94 points.reduce((sum, p) => sum + p[0], 0) / points.length,95 points.reduce((sum, p) => sum + p[1], 0) / points.length,96];9798export function crumpleSegments(args: {99 width: number;100 height: number;101 segments?: number;102 layers?: number;103 crushTo?: number;104 randomness?: number;105 seed?: string;106}): CrumpleSegment[] {107// … truncated
What it pulls in
npm packages
Other registry items
Files it writes
More from remocn
All 282 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| UI Accordionaccordion | remocn | Components | Free | 1 dep · 2 files | |
| UI AI Prompt Flowai-prompt-flow | remocn | Components | Free | 1 dep | |
| UI Alert Dialogalert-dialog | remocn | Components | Free | 1 dep · 2 files | |
| Animated Bar Chartanimated-bar-chart | remocn | Components | Free | 1 dep | |
| Animated Line Chartanimated-line-chart | remocn | Components | Free | 1 dep | |
| ASCII Dissolveascii-dissolve | remocn | Components | Free | 2 deps | |
| ASCII Renderascii-render | remocn | Components | Free | 1 dep | |
| Backdropbackdrop | remocn | Components | Free | 1 dep |
