Created
February 23, 2023 08:53
-
-
Save lgastler/0c10b0f80b78ed6d10c5578153fc6872 to your computer and use it in GitHub Desktop.
BackgroundBlur
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
import SwiftUI | |
struct BackgroundBlob: View { | |
@State private var rotationAmount = 0.0 | |
let alignment: Alignment = [.topLeading, .topTrailing, .bottomLeading, .bottomTrailing].randomElement()! | |
let color: Color = [.blue, .cyan, .indigo, .mint, .purple, .teal].randomElement()! | |
var body: some View { | |
Ellipse() | |
.fill(color) | |
.frame(width: .random(in: 200...500), height: .random(in: 200...500)) | |
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: alignment) | |
.offset(x: .random(in: -400...400), y: .random(in: -400...400)) | |
.rotationEffect(.degrees(rotationAmount)) | |
.animation(.linear(duration: .random(in: 20...40)).repeatForever(), value: rotationAmount) | |
.onAppear { | |
rotationAmount = .random(in: -360...360) | |
} | |
.blur(radius: 75) | |
} | |
} | |
struct ContentView: View { | |
var body: some View { | |
ZStack { | |
ForEach(0..<15) { _ in | |
BackgroundBlob() | |
} | |
} | |
.background(.blue) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment