-
Notifications
You must be signed in to change notification settings - Fork 53
/
Copy pathFireworks.swift
70 lines (64 loc) · 2.3 KB
/
Fireworks.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
//
// Fireworks.swift
// Vortex
// https://www.github.com/twostraws/Vortex
// See LICENSE for license information.
//
import SwiftUI
extension VortexSystem {
/// A built-in fireworks effect, using secondary systems that create sparkles and explosions.
/// Relies on a "circle" tag being present, which should be set to use
/// `.blendMode(.plusLighter)`.
public static let fireworks = VortexSystem(.fireworks)
}
extension VortexSystem.Settings {
public static let fireworks = VortexSystem.Settings { settings in
var sparkles = VortexSystem.Settings { sparkle in
sparkle.tags = ["circle"]
sparkle.spawnOccasion = .onUpdate
sparkle.emissionLimit = 1
sparkle.lifespan = 0.5
sparkle.speed = 0.05
sparkle.angleRange = .degrees(180)
sparkle.size = 0.05
}
var explosions = VortexSystem.Settings { explosion in
explosion.tags = ["circle"]
explosion.spawnOccasion = .onDeath
explosion.position = [0.5, 0.5]
explosion.birthRate = 100_000
explosion.emissionLimit = 500
explosion.speed = 0.5
explosion.speedVariation = 1
explosion.angleRange = .degrees(360)
explosion.acceleration = [0, 1.5]
explosion.dampingFactor = 4
explosion.colors = .randomRamp(
[.white, .pink, .pink],
[.white, .blue, .blue],
[.white, .green, .green],
[.white, .orange, .orange],
[.white, .cyan, .cyan]
)
explosion.size = 0.15
explosion.sizeVariation = 0.1
explosion.sizeMultiplierAtDeath = 0
}
settings.tags = ["circle"]
settings.secondarySettings = [sparkles, explosions]
settings.position = [0.5, 1]
settings.birthRate = 2
settings.emissionLimit = 1000
settings.speed = 1.5
settings.speedVariation = 0.75
settings.angleRange = .degrees(60)
settings.dampingFactor = 2
settings.size = 0.15
settings.stretchFactor = 4
}
}
#Preview("Fireworks") {
VortexView(.fireworks)
.navigationSubtitle("Demonstrates multi-stage effects")
.ignoresSafeArea(edges: .top)
}