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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
|
import SwiftUI
/// High-fidelity vector bomb illustration with interactive spark and fuse animations.
public struct AnimatedBombView: View {
public var size: CGFloat = 80
public var isDetonating: Bool = false
public var onClick: (() -> Void)? = nil
@State private var sparkPhase: Double = 0
@State private var hoverState: Bool = false
public init(size: CGFloat = 80, isDetonating: Bool = false, onClick: (() -> Void)? = nil) {
self.size = size
self.isDetonating = isDetonating
self.onClick = onClick
}
public var body: some View {
Button(action: {
onClick?()
}) {
ZStack {
// Glow behind the bomb when detonating
if isDetonating {
Circle()
.fill(
RadialGradient(
colors: [BubombTheme.accentOrange.opacity(0.4), Color.clear],
center: .center,
startRadius: size * 0.2,
endRadius: size * 0.8
)
)
.scaleEffect(1.2)
}
Canvas { context, canvasSize in
let w = canvasSize.width
let h = canvasSize.height
let scale = min(w, h) / 100.0
// 1. Fuse (Curved rope)
var fuse = Path()
fuse.move(to: CGPoint(x: 50 * scale, y: 35 * scale))
fuse.addCurve(
to: CGPoint(x: 75 * scale, y: 18 * scale),
control1: CGPoint(x: 50 * scale, y: 20 * scale),
control2: CGPoint(x: 65 * scale, y: 15 * scale)
)
context.stroke(
fuse,
with: .color(Color(red: 0.65, green: 0.55, blue: 0.40)),
lineWidth: 4 * scale
)
// 2. Collar / Cap
let collarRect = CGRect(x: 42 * scale, y: 28 * scale, width: 16 * scale, height: 9 * scale)
let collarPath = Path(roundedRect: collarRect, cornerRadius: 2 * scale)
context.fill(
collarPath,
with: .linearGradient(
Gradient(colors: [Color(red: 0.25, green: 0.25, blue: 0.30), Color(red: 0.15, green: 0.15, blue: 0.18)]),
startPoint: CGPoint(x: 50 * scale, y: 28 * scale),
endPoint: CGPoint(x: 50 * scale, y: 37 * scale)
)
)
// 3. Main Bomb Sphere
let sphereRect = CGRect(x: 15 * scale, y: 33 * scale, width: 70 * scale, height: 70 * scale)
let spherePath = Path(ellipseIn: sphereRect)
context.fill(
spherePath,
with: .radialGradient(
Gradient(colors: [
Color(red: 0.28, green: 0.29, blue: 0.34),
Color(red: 0.14, green: 0.14, blue: 0.17),
Color(red: 0.08, green: 0.08, blue: 0.10)
]),
center: CGPoint(x: 40 * scale, y: 55 * scale),
startRadius: 5 * scale,
endRadius: 38 * scale
)
)
// 4. Specular gloss highlight (Upper-left shine)
var gloss = Path()
gloss.addArc(
center: CGPoint(x: 36 * scale, y: 52 * scale),
radius: 24 * scale,
startAngle: .degrees(190),
endAngle: .degrees(260),
clockwise: false
)
context.stroke(
gloss,
with: .color(Color.white.opacity(0.35)),
style: StrokeStyle(lineWidth: 3.5 * scale, lineCap: .round)
)
// 5. Mischievous cute eyes (Restrained, subtle)
let leftEye = Path(ellipseIn: CGRect(x: 42 * scale, y: 64 * scale, width: 4 * scale, height: 5.5 * scale))
let rightEye = Path(ellipseIn: CGRect(x: 54 * scale, y: 64 * scale, width: 4 * scale, height: 5.5 * scale))
context.fill(leftEye, with: .color(Color.white.opacity(0.85)))
context.fill(rightEye, with: .color(Color.white.opacity(0.85)))
// Eye pupils / shine
let leftShine = Path(ellipseIn: CGRect(x: 43.5 * scale, y: 65 * scale, width: 1.8 * scale, height: 1.8 * scale))
let rightShine = Path(ellipseIn: CGRect(x: 55.5 * scale, y: 65 * scale, width: 1.8 * scale, height: 1.8 * scale))
context.fill(leftShine, with: .color(Color.black))
context.fill(rightShine, with: .color(Color.black))
// 6. Spark at fuse tip
let sparkCenter = CGPoint(x: 75 * scale, y: 18 * scale)
let sparkRadius = (isDetonating ? 12 : 6) * scale
// Spark Outer Glow
context.fill(
Path(ellipseIn: CGRect(
x: sparkCenter.x - sparkRadius,
y: sparkCenter.y - sparkRadius,
width: sparkRadius * 2,
height: sparkRadius * 2
)),
with: .radialGradient(
Gradient(colors: [
BubombTheme.accentOrange,
BubombTheme.accentAmber.opacity(0.5),
Color.clear
]),
center: sparkCenter,
startRadius: 1 * scale,
endRadius: sparkRadius
)
)
// Spark Core
context.fill(
Path(ellipseIn: CGRect(
x: sparkCenter.x - 2.5 * scale,
y: sparkCenter.y - 2.5 * scale,
width: 5 * scale,
height: 5 * scale
)),
with: .color(Color(red: 1.0, green: 0.95, blue: 0.4))
)
}
.frame(width: size, height: size)
}
.scaleEffect(hoverState ? 1.05 : 1.0)
.animation(.spring(response: 0.25, dampingFraction: 0.7), value: hoverState)
}
.buttonStyle(.plain)
.onHover { isHovered in
self.hoverState = isHovered
}
}
}
|