Skip to content

Instantly share code, notes, and snippets.

@xiangyu-sun
Created February 21, 2023 13:36
Show Gist options
  • Save xiangyu-sun/ee13e4c59b46bee644b6ff7e1e970ebe to your computer and use it in GitHub Desktop.
Save xiangyu-sun/ee13e4c59b46bee644b6ff7e1e970ebe to your computer and use it in GitHub Desktop.
struct TaichiView: View {
@State private var rotation = 0.0
var body: some View {
ZStack {
// Taichi symbol
ZStack {
// Yang
Path { path in
let radius = 80.0
let yinYangRadius = radius / 2.0
let center = CGPoint(x: radius, y: radius)
path.addArc(center: center, radius: CGFloat(radius), startAngle: Angle(degrees: 90), endAngle: Angle(degrees: 270), clockwise: true)
path.addArc(center: center, radius: CGFloat(radius), startAngle: Angle(degrees: 270), endAngle: Angle(degrees: 90), clockwise: true)
path.move(to: CGPoint(x: radius + yinYangRadius, y: radius))
path.addArc(center: CGPoint(x: radius + yinYangRadius, y: radius), radius: CGFloat(yinYangRadius), startAngle: Angle(degrees: 0), endAngle: Angle(degrees: 180), clockwise: true)
// Add smaller circle for yin
let smallRadius = yinYangRadius * 0.7
let smallCenter = CGPoint(x: radius + yinYangRadius - smallRadius, y: radius)
path.addArc(center: smallCenter, radius: CGFloat(smallRadius), startAngle: Angle(degrees: 90), endAngle: Angle(degrees: 270), clockwise: true)
}
.fill(Color.black)
.frame(width: 160, height: 160)
// Yin
Path { path in
let radius = 80.0
let yinYangRadius = radius / 2.0
let center = CGPoint(x: radius, y: radius)
path.addArc(center: center, radius: CGFloat(radius), startAngle: Angle(degrees: 90), endAngle: Angle(degrees: 270), clockwise: true)
path.addArc(center: center, radius: CGFloat(radius), startAngle: Angle(degrees: 270), endAngle: Angle(degrees: 90), clockwise: true)
path.move(to: CGPoint(x: yinYangRadius, y: radius))
path.addArc(center: CGPoint(x: yinYangRadius, y: radius), radius: CGFloat(yinYangRadius), startAngle: Angle(degrees: 0), endAngle: Angle(degrees: 180), clockwise: false)
// Add smaller circle for yang
let smallRadius = yinYangRadius * 0.7
let smallCenter = CGPoint(x: yinYangRadius + smallRadius, y: radius)
path.addArc(center: smallCenter, radius: CGFloat(smallRadius), startAngle: Angle(degrees: 90), endAngle: Angle(degrees: 270), clockwise: false)
}
.fill(Color.white)
.frame(width: 160, height: 160)
}
// Hare image
Image(systemName: "hare.fill")
.resizable()
.scaledToFit()
.frame(width: 60, height: 60)
}
.rotationEffect(.degrees(rotation))
.onAppear {
rotation = 360.0
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment