Skip to content

Instantly share code, notes, and snippets.

@veeneck
Created May 27, 2018 01:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save veeneck/ecd0790dbfbfeafdf3d2c6d9b6090b2c to your computer and use it in GitHub Desktop.
Save veeneck/ecd0790dbfbfeafdf3d2c6d9b6090b2c to your computer and use it in GitHub Desktop.
Create a Sunburst in SpriteKit
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
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment