Created
May 27, 2018 01:47
-
-
Save veeneck/ecd0790dbfbfeafdf3d2c6d9b6090b2c to your computer and use it in GitHub Desktop.
Create a Sunburst in SpriteKit
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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