-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathContentView.swift
228 lines (183 loc) Β· 7.82 KB
/
ContentView.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
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
import SwiftUI
import SpriteKit
import SceneKit
import AVFoundation
struct ContentView: View {
// MARK: - properties
@State var progress : CGFloat = 0.8
@State var startAnimation : CGFloat = 0
@State var angleMultiplyer : AbsoluteDirec = .WEST
@State var earthRotating : AbsoluteDirec = .WEST
@State var isMoonStopped : IsMoonStopped = .MOVE
@State var windCount : CGFloat = 1
@State var isGraduationTapped : Bool = false
@State var isMusicOn : Bool = false
@State var player : AVAudioPlayer!
@State var time : String = "12:00"
@State var moonEmoji : String = "π"
var SkyColors : [Color] {
switch earthRotating {
case .WEST :
return [.white, .blue]
case .SOUTH :
return [.orange,.red, .blue]
case .EAST :
return [.black, .blue]
case .NORTH :
return [.blue,.orange, .white]
default:
return [.white, .blue]
}
}
init(){
UINavigationBar.appearance().titleTextAttributes = [.foregroundColor: UIColor.white]
}
var body: some View {
NavigationView {
// MARK: - FirstView
VStack(spacing:10){
Spacer()
HStack(spacing : 30) {
// Earth Move
Button {
earthRotating = AbsoluteDirec(rawValue: (earthRotating.rawValue) % 4 + 1)!
print(earthRotating)
isMoonStopped = .STOP
switch earthRotating {
case .SOUTH :
time = "18:00"
case .EAST :
time = "24:00"
case .NORTH :
time = "6:00"
default:
time = "12:00"
}
if angleMultiplyer.rawValue % 2 != 0 {
if abs(angleMultiplyer.rawValue-earthRotating.rawValue) % 2 == 0 {
progress = 0.8
}
else{
progress = 0.1
}
} else{
if abs(angleMultiplyer.rawValue - earthRotating.rawValue) % 2 == 0 {
progress = 0.4
}
else{
progress = 0.1
}
}
} label: {
Label {
Text("Move")
} icon: {
Image(systemName: "globe.europe.africa.fill")
}
.foregroundColor(.white)
}
// Moon Move
Button {
angleMultiplyer = AbsoluteDirec(rawValue:(angleMultiplyer.rawValue) % 4 + 1)!
progress = angleMultiplyer.rawValue % 2 == 0 ? 0.4 : 0.8
isMoonStopped = .MOVE
switch angleMultiplyer {
case .SOUTH :
moonEmoji = "π"
case .EAST :
moonEmoji = "π"
case .NORTH :
moonEmoji = "π"
default:
moonEmoji = "π"
}
} label: {
Label {
Text("Move")
} icon: {
Image(systemName: "moon.circle.fill")
}
.foregroundColor(.white)
}
}
// Graduation
Label {
Text("Graduation")
} icon: {
Image(systemName: "chart.xyaxis.line")
}
.onTapGesture {
isGraduationTapped.toggle()
if isMoonStopped == .MOVE {
isMoonStopped = .EXTRA
}
}
.foregroundColor(.white)
.padding(.vertical)
// SCNSceneView
SceneKitView(angleMultiplyer: $angleMultiplyer,earthRotating : $earthRotating ,isMoonStopped: $isMoonStopped)
.frame(width: UIScreen.main.bounds.width, height: UIScreen.main.bounds.height/2)
.padding()
// Moonshape and Time
Text("\(moonEmoji) \(isMoonStopped != .STOP ? "" : time)")
.font(.title)
.foregroundColor(.white)
.bold()
Spacer()
}
.navigationTitle("Position with S,E,M")
.navigationBarTitleDisplayMode(.inline)
.background(.black)
.toolbar(content: {
ToolbarItem(placement: .navigationBarTrailing) {
Button {
isMusicOn.toggle()
if isMusicOn {
playSound()
if isMoonStopped == .MOVE {
isMoonStopped = .EXTRA
} } else{
player?.stop()
}
} label: {
Image(systemName: isMusicOn ? "speaker.wave.2.fill": "speaker.slash.fill")
.foregroundColor(.white)
}
}
})
// MARK: - SecondView
VStack {
GeometryReader{ proxy in
let size = proxy.size
ZStack{
WaterWave(progress: $progress, waveHeight: 0.1, offset: startAnimation)
.fill(Color.blue)
if isGraduationTapped{
GraduationView()
.frame(width: UIScreen.main.bounds.width, height: UIScreen.main.bounds.height)
}
}.frame(width: size.width, height: size.height, alignment: .center)
.onAppear {
withAnimation(.easeIn(duration: 6).repeatForever(autoreverses : false)){
startAnimation = size.width*1.5
}
}
}
}
.background(LinearGradient(gradient: Gradient(colors: isMoonStopped == .STOP ? SkyColors : [.white, .blue]), startPoint: .top, endPoint: .bottom))
}.navigationViewStyle(.columns)
}
func playSound(){
let url = Bundle.main.url(forResource: "waveMusic", withExtension: "mp3")
guard url != nil else{
return
}
do{
player = try AVAudioPlayer(contentsOf: url!)
player?.play()
}
catch{
print("error")
}
}
}