Skip to content

Instantly share code, notes, and snippets.

@veeneck
Created May 27, 2018 01:47
Show Gist options
  • Select an option

  • Save veeneck/ecd0790dbfbfeafdf3d2c6d9b6090b2c to your computer and use it in GitHub Desktop.

Select an option

Save veeneck/ecd0790dbfbfeafdf3d2c6d9b6090b2c to your computer and use it in GitHub Desktop.

Revisions

  1. Ryan Campbell created this gist May 27, 2018.
    23 changes: 23 additions & 0 deletions sunburst.swift
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,23 @@
    let radius: CGFloat = 150 / 2.0
    let bezierPath = CGMutablePath()
    let centerPoint = CGPoint(x: 0, y: 0)
    var thisPoint = CGPoint(x: radius, y: 0)
    bezierPath.move(to: centerPoint)
    var thisAngle: CGFloat = 90
    let unitCount: CGFloat = count
    let spacingDegrees: CGFloat = 6.0
    let sliceDegrees: CGFloat = 360.0 / unitCount - spacingDegrees

    for _ in 0..<Int(unitCount) {
    let x = radius * CGFloat(cosf(Float((thisAngle).degreesToRadians()))) + centerPoint.x
    let y = radius * CGFloat(sinf(Float((thisAngle).degreesToRadians()))) + centerPoint.y
    thisPoint = CGPoint(x: x, y: y)
    bezierPath.addLine(to: thisPoint)
    thisAngle += sliceDegrees
    let x2 = radius * CGFloat(cosf(Float((thisAngle).degreesToRadians()))) + centerPoint.x
    let y2 = radius * CGFloat(sinf(Float((thisAngle).degreesToRadians()))) + centerPoint.y
    thisPoint = CGPoint(x: x2, y: y2)
    bezierPath.addLine(to: thisPoint)
    bezierPath.addLine(to: centerPoint)
    thisAngle += spacingDegrees
    }