← Files Pray Production StudioARCHIVED FILE
skills/pps-ads/packages/remotion-kit/src/motion/grid.ts
946 Bytes · Oct 8, 2026 · 06:29 UTC
import { MOTION, MUSIC_BPM, type MusicTempo } from '../grammar'
export function bpmFor(tempo: MusicTempo | undefined): number {
return MUSIC_BPM[tempo ?? 'mid']
}
/** An eighth note: half a beat. Canvas entrances land on this grid. */
export function gridSeconds(bpm: number): number {
return 60 / bpm / 2
}
export function quantizeToGrid(seconds: number, bpm: number): number {
const grid = gridSeconds(bpm)
return Math.round(seconds / grid) * grid
}
/**
* n entrance times. Canvas-beat entrances land on the grid (the first is quantized, so 0 stays 0); the tiles inside
* a beat then follow at the tile rate (tileStaggerMs), not a whole grid step, which would be 2 to 4 times too slow.
*/
export function staggerOnGrid(count: number, bpm: number): number[] {
const first = quantizeToGrid(0, bpm)
const gap = MOTION.tileStaggerMs / 1000
return Array.from({ length: count }, (_, i) => Number((first + i * gap).toFixed(6)))
}
SHA-256: 8225c61b37edb4308344c837000dd56eb556643449a81ad9ca4fb1162cb5d2e4