A beautiful, lightweight confetti animation package for SwiftUI applications. This package provides easy-to-use components for adding celebration animations to your macOS apps with minimal effort.
- 🎉 Ready-to-use confetti animation view
- 🎨 Multiple confetti shapes and colors
- 🔄 Physics-based animation with proper rotations and movement
- 🚀 Built with modern Swift features (@Observable, SwiftUI Canvas)
- 📦 Simple Swift Package Manager integration
- macOS 14.0+
- Swift 5.9+
- Xcode 15.0+
Add the following to your Package.swift file:
dependencies: [
.package(url: "https://github.com/taricsa/Confetti_Effects.git", from: "1.0.0")
]Or add it directly from Xcode:
- Go to
File>Add Package Dependencies... - Paste the repository URL:
https://github.com/taricsa/Confetti_Effects.git - Click
Add Package
import SwiftUI
import Confetti_Effects
struct ContentView: View {
var body: some View {
ConfettiCanvasView()
.frame(width: 400, height: 400)
}
}The ConfettiCanvasView includes a "Launch Confetti" button at the bottom that triggers a confetti burst when tapped.
If you want more control over when the confetti animation plays, you can use the ParticleSystem class directly:
import SwiftUI
import Confetti_Effects
struct CustomConfettiView: View {
@State private var particleSystem = ParticleSystem()
@State private var canvasSize: CGSize = .zero
var body: some View {
TimelineView(.animation) { timeline in
Canvas { context, size in
// Store canvas size
if canvasSize != size {
canvasSize = size
}
// Update particle physics
let now = timeline.date.timeIntervalSinceReferenceDate
particleSystem.update(date: now, size: size)
// Draw particles
for particle in particleSystem.particles {
// Drawing code here...
}
}
.overlay(alignment: .bottom) {
Button("Custom Confetti!") {
// Customize confetti properties
let origin = CGPoint(x: canvasSize.width / 2, y: canvasSize.height)
particleSystem.emitBurst(
count: 200,
origin: origin,
size: canvasSize,
emissionAngleRange: Angle.degrees(-160)...Angle.degrees(-20),
initialVelocityRange: 200...500
)
}
.padding()
}
}
}
}The emitBurst method allows you to customize various aspects of the confetti animation:
func emitBurst(
count: Int,
origin: CGPoint,
size: CGSize,
emissionAngleRange: ClosedRange<Angle> = Angle.degrees(-120)...Angle.degrees(-60),
initialVelocityRange: ClosedRange<Double> = 150.0...400.0,
lifespanRange: ClosedRange<TimeInterval> = 3.0...6.0,
angularVelocityRange: ClosedRange<Double> = -Double.pi...Double.pi
)| Parameter | Description |
|---|---|
count |
Number of confetti particles to create |
origin |
Starting position for the particles |
size |
Current canvas size |
emissionAngleRange |
Range of angles for initial velocity (in degrees, upwards) |
initialVelocityRange |
Range of initial speeds (points per second) |
lifespanRange |
Range of particle lifetimes (in seconds) |
angularVelocityRange |
Range of rotation speeds (radians per second) |
This project is licensed under the MIT License - see the LICENSE file for details.
- Built with SwiftUI and the Canvas API
- Inspired by various confetti implementations in the iOS/macOS community
Taric Andrade - GitHub: @taricsa
Feel free to reach out with any questions, issues, or suggestions!