-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathMagic.swift
55 lines (49 loc) · 1.39 KB
/
Magic.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
//
// Magic.swift
//
//
// Created by Ben Myers on 3/22/24.
//
import SwiftUI
import Particles
import Foundation
public extension Preset {
struct Magic: Entity, PresetEntry {
var color: Color
var spawnPoint: UnitPoint
public var body: some Entity {
Emitter(every: 0.03) {
Particle {
RadialGradient(
colors: [color, .clear],
center: .center,
startRadius: 0.0,
endRadius: 10.0
)
.clipShape(Circle())
.frame(width: 15.0, height: 15.0)
}
.initialPosition(.center)
.initialVelocity { c in
.init(angle: .random(), magnitude: .random(in: 0.3 ... 0.5))
}
.fixVelocity{ c in
return .init(dx: c.proxy.velocity.dx + c.timeAlive * 0.02 * sin(5 * (c.proxy.seed.0 - 0.5) * c.timeAlive), dy: c.proxy.velocity.dy - c.timeAlive * 0.02 * cos(5 * (c.proxy.seed.1 - 0.5) * c.timeAlive))
}
.blendMode(.plusLighter)
.hueRotation(angleIn: .degrees(-10.0) ... .degrees(10.0))
.transition(.twinkle, on: .death, duration: 2.0)
.transition(.opacity, on: .birth, duration: 0.5)
.lifetime(3)
.glow(color, radius: 4)
}
}
public init(
color: Color = .purple,
spawnPoint: UnitPoint = .center
) {
self.color = color
self.spawnPoint = spawnPoint
}
}
}