Created
September 27, 2020 12:27
-
-
Save laevandus/e6555bb234f59e9effdfd5a411467890 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct ContentView: View { | |
@State private var amplitude = 10.0 | |
@State private var frequency = 0.1 | |
var body: some View { | |
ZStack { | |
Wave(amplitude: amplitude, frequency: frequency) | |
.fill(Color.blue) | |
.frame(height: 300.0) | |
.animation(.easeInOut(duration: 3)) | |
Button(action: toggleAnimation, label: { | |
Text("Animate") | |
}) | |
.padding(4) | |
.background(Color.red) | |
.cornerRadius(8) | |
.foregroundColor(.white) | |
} | |
} | |
func toggleAnimation() { | |
amplitude = amplitude <= 15.0 ? Double.random(in: 30.0...60.0) : Double.random(in: 5.0...15.0) | |
frequency = frequency <= 0.2 ? Double.random(in: 0.2...0.4) : Double.random(in: 0.05...0.2) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment