Fireworks Background
animate-ui/components-backgrounds-fireworksFreeComponent
A background component that displays a fireworks animation.
Install it
npx shadcn@latest add https://animate-ui.com/r/components-backgrounds-fireworks.jsonSource
1'use client';23import * as React from 'react';45import { cn } from '@/lib/utils';67const rand = (min: number, max: number): number =>8 Math.random() * (max - min) + min;910const randInt = (min: number, max: number): number =>11 Math.floor(Math.random() * (max - min) + min);1213const randColor = (): string => `hsl(${randInt(0, 360)}, 100%, 50%)`;1415type ParticleType = {16 x: number;17 y: number;18 color: string;19 speed: number;20 direction: number;21 vx: number;22 vy: number;23 gravity: number;24 friction: number;25 alpha: number;26 decay: number;27 size: number;28 update: () => void;29 draw: (ctx: CanvasRenderingContext2D) => void;30 isAlive: () => boolean;31};3233function createParticle(34 x: number,35 y: number,36 color: string,37 speed: number,38 direction: number,39 gravity: number,40 friction: number,41 size: number,42): ParticleType {43 const vx = Math.cos(direction) * speed;44 const vy = Math.sin(direction) * speed;45 const alpha = 1;46 const decay = rand(0.005, 0.02);4748 return {49 x,50 y,51 color,52 speed,53 direction,54 vx,55 vy,56 gravity,57 friction,58 alpha,59 decay,60 size,61 update() {62 this.vx *= this.friction;63 this.vy *= this.friction;64 this.vy += this.gravity;65 this.x += this.vx;66 this.y += this.vy;67 this.alpha -= this.decay;68 },69 draw(ctx: CanvasRenderingContext2D) {70 ctx.save();71 ctx.globalAlpha = this.alpha;72 ctx.beginPath();73 ctx.arc(this.x, this.y, this.size, 0, Math.PI * 2);74 ctx.fillStyle = this.color;75 ctx.fill();76 ctx.restore();77 },78 isAlive() {79 return this.alpha > 0;80 },81 };82}8384type FireworkType = {85 x: number;86 y: number;87 targetY: number;88 color: string;89 speed: number;90 size: number;91 angle: number;92 vx: number;93 vy: number;94 trail: { x: number; y: number }[];95 trailLength: number;96 exploded: boolean;97 update: () => boolean;98 explode: () => void;99 draw: (ctx: CanvasRenderingContext2D) => void;100};101102function createFirework(103 x: number,104 y: number,105 targetY: number,106 color: string,107 speed: number,108 size: number,109 particleSpeed: { min: number; max: number } | number,110 particleSize: { min: number; max: number } | number,111 onExplode: (particles: ParticleType[]) => void,112): FireworkType {113 const angle = -Math.PI / 2 + rand(-0.3, 0.3);114 const vx = Math.cos(angle) * speed;115 const vy = Math.sin(angle) * speed;116 const trail: { x: number; y: number }[] = [];117 const trailLength = randInt(10, 25);118119// … truncated
Files it writes
More from Animate UI
All 580 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Avatar Groupcomponents-animate-avatar-group | Animate UI | Components | Free | 1 dep | |
| Codecomponents-animate-code | Animate UI | Components | Free | 1 dep | |
| Code Tabscomponents-animate-code-tabs | Animate UI | Components | Free | 1 dep | |
| Cursorcomponents-animate-cursor | Animate UI | Components | Free | no deps | |
| GitHub Stars Wheelcomponents-animate-github-stars-wheel | Animate UI | Components | Free | 1 dep | |
| Tabscomponents-animate-tabs | Animate UI | Components | Free | no deps | |
| Tooltipcomponents-animate-tooltip | Animate UI | Components | Free | 1 dep | |
| Bubble Backgroundcomponents-backgrounds-bubble | Animate UI | Components | Free | 1 dep |
