Skip to content

Instantly share code, notes, and snippets.

@dfrobison
Last active April 3, 2020 14:39
Show Gist options
  • Save dfrobison/6f43fb4ad1e875a227f168e6518b9168 to your computer and use it in GitHub Desktop.
Save dfrobison/6f43fb4ad1e875a227f168e6518b9168 to your computer and use it in GitHub Desktop.
extension CGSize {
public static func + (lhs: CGSize, rhs: CGSize) -> CGSize {
CGSize(width: lhs.width+rhs.width,
height: lhs.height+rhs.height)
}
public static func += (lhs: inout CGSize, rhs: CGSize) {
lhs.width += rhs.width
lhs.height += rhs.height
}
}
struct WobblyCone: View {
@State private var offset: CGSize = .zero
@State private var dragState: CGSize = .zero
private let hueColors: [Double] = stride(from: 0, to: 1, by: 0.04).map({$0})
var body: some View {
let gesture = DragGesture()
.onChanged({ self.dragState = $0.translation })
.onEnded({ (value) in
self.offset += value.translation
self.dragState = .zero
})
return ZStack {
ForEach(hueColors, id: \.self) { (hue) in
Circle()
.fill(Color(hue: hue, saturation: 1, brightness: 1))
.padding()
.scaleEffect(CGFloat(1.0-hue))
.offset(self.offset + self.dragState)
.gesture(gesture)
.animation(.easeInOut(duration: 1 + 2*hue))
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment