💣 Glitterbomb
A pure Rust confetti animation library for WebAssembly. No JavaScript required.
Features
- 🦀 Pure Rust - No JS dependencies, compiles to WebAssembly
- 🎨 Customizable - Colors, shapes, physics, and more
- ⚡ Lightweight - Minimal dependencies, small WASM binary
- 🎮 Preset Effects - Celebration, fireworks, snow, cannon
- ♿ Accessible - Respects
prefers-reduced-motion - 🔧 Framework Agnostic - Works with Dioxus, Leptos, Yew, or vanilla WASM
Installation
Quick Start
use ;
// Fire with defaults
confetti;
Usage with Dioxus
use *;
use ;
Preset Effects
use ;
// Fire from both sides of the screen
celebration;
// Explode from the center like fireworks
fireworks;
// Gentle falling snow effect
snow;
// Blast from the bottom of the screen
cannon;
Configuration Options
| Option | Type | Default | Description |
|---|---|---|---|
particle_count |
u32 |
50 |
Number of confetti particles |
angle |
f64 |
90.0 |
Launch angle in degrees (90 = up) |
spread |
f64 |
45.0 |
Spread angle in degrees |
start_velocity |
f64 |
45.0 |
Initial particle velocity |
decay |
f64 |
0.9 |
Velocity decay rate (0.0 - 1.0) |
gravity |
f64 |
1.0 |
Gravity multiplier |
drift |
f64 |
0.0 |
Horizontal drift |
ticks |
u32 |
200 |
Animation duration (~60 ticks/sec) |
origin |
Origin |
{x: 0.5, y: 0.5} |
Emission point (0.0 - 1.0) |
shapes |
Vec<Shape> |
[Square, Circle] |
Particle shapes |
colors |
Vec<Color> |
Rainbow palette | Particle colors |
scalar |
f64 |
1.0 |
Size multiplier |
z_index |
i32 |
100 |
CSS z-index for canvas |
flat |
bool |
false |
Disable wobble/rotation |
disable_for_reduced_motion |
bool |
false |
Respect accessibility setting |
Shapes
use Shape;
let opts = ConfettiOptions ;
Colors
use Color;
// From hex string
let red = from_hex;
let short = from_hex; // Shorthand works too
// From RGB values
let green = new;
// Predefined constants
let blue = BLUE;
let white = WHITE;
Custom Canvas
Render confetti on a specific canvas element instead of a fullscreen overlay:
use ;
use HtmlCanvasElement;
Stop Animation
use reset;
// Stop all confetti and remove the canvas
reset;
Accessibility
The library respects the prefers-reduced-motion media query when enabled:
confetti;
Comparison with canvas-confetti
This is a Rust port inspired by canvas-confetti. Key differences:
| Feature | canvas-confetti | glitterbomb |
|---|---|---|
| Language | JavaScript | Rust/WASM |
| Bundle size | ~15kb min | ~30kb WASM |
| Web Workers | ✅ | ❌ (WASM is fast enough) |
| Custom paths | ✅ | ❌ (coming soon) |
| Text shapes | ✅ | ❌ (coming soon) |
| Bitmap shapes | ✅ | ❌ |
License
MIT License - see LICENSE for details.
Contributing
Contributions welcome! Please feel free to submit a Pull Request.