Skip to content

Instantly share code, notes, and snippets.

@The-Igor
Last active November 16, 2023 07:20
Show Gist options
  • Save The-Igor/8501777f7df41e0276080d255ebef9e0 to your computer and use it in GitHub Desktop.
Save The-Igor/8501777f7df41e0276080d255ebef9e0 to your computer and use it in GitHub Desktop.
struct ContentView: View {
let columns: Int = 28
var body: some View{
ZStack{
Color.clear
HStack(spacing: 0){
ForEach(0..<columns, id:\.self){ i in
ColumnView(delay: 0, offsetY: offsetY(i), color: .blue)
}
}
.overlay(
Image("apple")
.resizable()
.renderingMode(.template)
.foregroundColor(.black.opacity(0.5))
.blur(radius: 2)
.frame(width: 250, height: 250)
.blendMode(.colorBurn)
)
}
.overlay(
Image("WWDC 24")
.renderingMode(.template)
.resizable()
.scaledToFit()
.foregroundColor(.blue)
.padding(.horizontal, 50)
.padding(.bottom, 25)
,
alignment: .bottom
)
.preferredColorScheme(.dark)
}
private func offsetY(_ i: Int) -> CGFloat{
let half : Double = Double(columns) / 2
if Double(i) < half{
return 200 + (5 * Double(i))
}else{
return 200 + (5 * (half - (Double(i) - half)))
}
}
}
struct ColumnView: View{
let delay : CGFloat
let offsetY: CGFloat
let count : Int = 30
let color : Color
@State private var animate = false
var body: some View{
ZStack{
ForEach(0..<count, id : \.self){ i in
let delta : Double = 1 + (0.4 * Double(count - i))
Circle()
.fill(color)
.frame(width: delta)
.offset(y: animate ? -offsetY : offsetY)
.animation(
.easeOut(duration: 2)
.delay(1)
.repeatForever(autoreverses: true)
.delay(0.2 * delta + delay), value: animate)
}
}
.task{
animate.toggle()
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment