-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathFire.swift
59 lines (53 loc) · 1.62 KB
/
Fire.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
//
// Fire.swift
//
//
// Created by Ben Myers on 1/21/24.
//
import SwiftUI
import Particles
import Foundation
public extension Preset {
struct Fire: Entity, PresetEntry {
var color: Color
var spawnPoint: UnitPoint
var spawnRadius: CGSize
var flameSize: CGFloat = 10.0
var flameLifetime: TimeInterval = 1
public var body: some Entity {
Emitter(every: 0.01) {
Particle {
RadialGradient(
colors: [color, .clear],
center: .center,
startRadius: 0.0,
endRadius: flameSize * 0.8
)
.clipShape(Circle())
}
.initialOffset(xIn: -spawnRadius.width/2 ... spawnRadius.width/2, yIn: -spawnRadius.height/2 ... spawnRadius.height/2)
.initialPosition(.center)
.hueRotation(angleIn: .degrees(0.0) ... .degrees(50.0))
.initialOffset(xIn: -spawnRadius.width/2 ... spawnRadius.width/2, yIn: -spawnRadius.height/2 ... spawnRadius.height/2)
.initialVelocity(xIn: -0.4 ... 0.4, yIn: -1 ... 0.5)
.fixAcceleration(y: -0.05)
.lifetime(in: 1 +/- 0.2)
.glow(color.opacity(0.5), radius: 18.0)
.blendMode(.plusLighter)
.transition(.scale, on: .death, duration: 0.5)
.transition(.opacity, on: .birth, duration: 0.3)
}
}
public init(
color: Color = .red,
spawnPoint: UnitPoint = .center,
flameSize: CGFloat = 10.0,
spawnRadius: CGSize = .init(width: 20.0, height: 4.0)
) {
self.color = color
self.spawnPoint = spawnPoint
self.flameSize = flameSize
self.spawnRadius = spawnRadius
}
}
}