BadgeBackground.swift


  1. import SwiftUI
  2. struct BadgeBackground: View {
  3. var body: some View {
  4. GeometryReader { geometry in
  5. Path { path in
  6. var width: CGFloat = min(geometry.size.width, geometry.size.height)
  7. let height = width
  8. let xScale: CGFloat = 0.832
  9. let xOffset = (width * (1.0 - xScale)) / 2.0
  10. width *= xScale
  11. path.move(
  12. to: CGPoint(
  13. x: width * 0.95 + xOffset,
  14. y: height * (0.20 + HexagonParameters.adjustment)
  15. )
  16. )
  17. HexagonParameters.segments.forEach { segment in
  18. path.addLine(
  19. to: CGPoint(
  20. x: width * segment.line.x + xOffset,
  21. y: height * segment.line.y
  22. )
  23. )
  24. path.addQuadCurve(
  25. to: CGPoint(
  26. x: width * segment.curve.x + xOffset,
  27. y: height * segment.curve.y
  28. ),
  29. control: CGPoint(
  30. x: width * segment.control.x + xOffset,
  31. y: height * segment.control.y
  32. )
  33. )
  34. }
  35. }
  36. .fill(Color.black)
  37. }
  38. }
  39. }
  40. struct BadgeBackground_Previews: PreviewProvider {
  41. static var previews: some View {
  42. BadgeBackground()
  43. }
  44. }