-
Notifications
You must be signed in to change notification settings - Fork 0
/
Playground Code
95 lines (71 loc) · 3.15 KB
/
Playground Code
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
import SwiftUI
import PlaygroundSupport
struct BreatheView: View {
@State private var numberCircles = 6.0
@State private var circleRadius = 50.0
@State private var innerRadius = 0.0
@State private var rotating = false
@State private var expanding = false
@State private var radiating = false
var body: some View {
ZStack {
ForEach([Int](1...Int(numberCircles)), id: \.self) { item in
Circle()
.fill(Color.blue)
.opacity(0.3)
.scaleEffect(self.expanding ? 4.2 : 1.0) //scale size
.frame(width: CGFloat(self.circleRadius), height: CGFloat(self.circleRadius))
.offset(x: self.xPosition(item), y: self.yPosition(item))
.animation(Animation
.easeIn(duration: 5.0)
.repeatForever(autoreverses: true)
)
} // ForEach
ForEach([Int](1...Int(numberCircles)), id: \.self) { item in
Circle()
.fill(Color.green)
.opacity(0.3)
.scaleEffect(self.expanding ? 4.0 : 0.8) //scale size
.frame(width: CGFloat(self.circleRadius), height: CGFloat(self.circleRadius))
.offset(x: self.xPosition(item), y: self.yPosition(item))
.animation(Animation
.easeIn(duration: 6.0)
.repeatForever(autoreverses: true)
)
} // ForEach
ForEach([Int](1...Int(numberCircles)), id: \.self) { item in
Circle()
.fill(Color.white)
.opacity(0.3)
.scaleEffect(self.expanding ? 3.0 : 0.5) //scale size
.frame(width: CGFloat(self.circleRadius), height: CGFloat(self.circleRadius))
.offset(x: self.xPosition(item), y: self.yPosition(item))
.animation(Animation
.easeIn(duration: 7.0)
.repeatForever(autoreverses: true)
)
} // ForEach
} // ZStack
.rotationEffect(.degrees(rotating ? 360 : 0))
.animation(
Animation.linear(duration: 30.0) // rotation duration
.repeatForever(autoreverses: false)
)
.onAppear(){
self.rotating.toggle()
self.expanding.toggle()
withAnimation {
self.innerRadius += 80
}
}
} // Body
func xPosition(_ item: Int ) -> CGFloat {
let xPosition = cos(Double(item)) * innerRadius
return CGFloat(xPosition)
}
func yPosition(_ item: Int ) -> CGFloat {
let yPosition = sin(Double(item)) * innerRadius
return CGFloat(yPosition)
}
} // View
PlaygroundPage.current.setLiveView(BreatheView())