Last active
August 30, 2024 05:52
-
-
Save random-yang/c2e9e9386e89cc674eaf290f8e02416a to your computer and use it in GitHub Desktop.
SwiftUI 0/20
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 GlowingSphere: View { | |
@State private var rotationAngle: Double = 0 | |
@State private var scales: [CGFloat] = [1.0, 1.0, 1.0, 1.0] | |
var body: some View { | |
ZStack { | |
// BG | |
Color.black.edgesIgnoringSafeArea(.all) | |
// Glowing Loop | |
ForEach(0..<4) { layer in | |
ForEach(0..<60) { i in | |
let R = 10 * Double.random(in: 0.1...1.0) | |
Circle() | |
.fill(Color.white.opacity(Double.random(in: 0.1...0.8))) | |
.frame(width: R, height: R) | |
.offset(y: -CGFloat(50 - layer * 10) * scales[layer]) | |
.rotationEffect(.degrees(Double(i) * 6 + rotationAngle)) | |
} | |
} | |
} | |
.onAppear { | |
for i in 0..<4 { | |
withAnimation(Animation.easeInOut(duration: 0.6).repeatForever(autoreverses: true).delay(Double(i) * 0.6/4)) { | |
scales[i] = 1.2 | |
} | |
} | |
} | |
} | |
} | |
struct ContentView: View { | |
var body: some View { | |
GlowingSphere() | |
} | |
} | |
#Preview { | |
ContentView() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment