Skip to content

Instantly share code, notes, and snippets.

@izakpavel
Created December 31, 2020 09:22
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save izakpavel/d9da24fb08b879723d882e6ee5be8c27 to your computer and use it in GitHub Desktop.
Save izakpavel/d9da24fb08b879723d882e6ee5be8c27 to your computer and use it in GitHub Desktop.
2021 WELCOME
import SwiftUI
struct CircularEffect: AnimatableModifier {
var param: CGFloat
let count: Int
let radius: CGFloat
var animatableData: CGFloat {
get { return param }
set { param = newValue }
}
func scale(_ index: Int)-> CGFloat {
return 1.5*sin(param*CGFloat.pi)*CGFloat(index)/CGFloat(count)
}
func opacity(_ index: Int)-> Double {
return index == count-1 ? 1.0 : 0.16*Double(index)/Double(count)
}
func innerRadius(_ index: Int)-> CGSize {
let ratio = 0.3+0.7*sin(param*CGFloat.pi)
return CGSize(width: cos(param*CGFloat.pi*2)*radius*ratio, height: sin(param*CGFloat.pi*2)*radius*ratio)
}
func body(content: Content) -> some View {
ZStack {
ForEach (0..<count) { index in
content
.hueRotation(Angle(degrees: Double(index)/Double(count)*90.0-90.0))
.scaleEffect(self.scale(index))
.rotationEffect(Angle(radians: Double.pi + Double(2*param*CGFloat.pi*2)))
.offset(self.innerRadius(index))
.rotationEffect(Angle(radians: Double(index)/Double(count)*Double.pi*2 + Double(param*CGFloat.pi*2)))
.opacity(self.opacity(index))
.blendMode(.plusLighter)
}
}
}
}
struct Year2021View: View {
@State var param: CGFloat = 0.0
var body: some View {
VStack {
Text("2021")
.font(.largeTitle)
.foregroundColor(Color("gold"))
//.modifier(CircularEffect(param: self.param, count: 3, radius: 21)) try to have fun with multiple effects ;)
.modifier(CircularEffect(param: self.param, count: 200, radius: 128))
}
.onTapGesture {
withAnimation(Animation.easeInOut(duration: 10.0).repeatForever(autoreverses: false)) {
self.param = 1.0
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment