Skip to content

Instantly share code, notes, and snippets.

@laevandus
Created September 27, 2020 12:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save laevandus/e6555bb234f59e9effdfd5a411467890 to your computer and use it in GitHub Desktop.
Save laevandus/e6555bb234f59e9effdfd5a411467890 to your computer and use it in GitHub Desktop.
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