Skip to content

Instantly share code, notes, and snippets.

@prafullakumar
Created June 16, 2020 15:36
Show Gist options
  • Save prafullakumar/fc780fdfd2a0b934424ff90e1e1141c0 to your computer and use it in GitHub Desktop.
Save prafullakumar/fc780fdfd2a0b934424ff90e1e1141c0 to your computer and use it in GitHub Desktop.
import SwiftUI
struct Diamond: Shape {
func path(in rect: CGRect) -> Path {
let (x, y, width, height) = rect.centeredSquare.flatten()
let lowerPoint = CGPoint(x: x + width / 2, y: (y + height ))
let path = Path { p in
p.move(to: lowerPoint)
p.addArc(center: CGPoint(x: x, y: (y + height)),
radius: (width / 2),
startAngle: .A360,
endAngle: .A270,
clockwise: true)
p.addArc(center: CGPoint(x: x, y: y),
radius: (width / 2),
startAngle: .A90,
endAngle: .zero,
clockwise: true)
p.addArc(center: CGPoint(x: x + width, y: y),
radius: (width / 2),
startAngle: .A180,
endAngle: .A90,
clockwise: true)
p.addArc(center: CGPoint(x: x + width, y: y + height),
radius: (width / 2),
startAngle: .A270 ,
endAngle: .A180,
clockwise: true)
}
return path
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment