Skip to content

Instantly share code, notes, and snippets.

@lgastler
Created February 23, 2023 08:53
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 lgastler/0c10b0f80b78ed6d10c5578153fc6872 to your computer and use it in GitHub Desktop.
Save lgastler/0c10b0f80b78ed6d10c5578153fc6872 to your computer and use it in GitHub Desktop.
BackgroundBlur
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