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