Drawing a circle in Swift using Bezier
The following Swift code produces the image you can see at the end of the post including the error messages.
import UIKit
import Darwin
var x,y: CGFloat
x = 10
y = 10
var point = CGPoint(x:100, y:100)
var radius: CGFloat = 50.0
let context = UIGraphicsGetCurrentContext()
var circle: UIBezierPath = UIBezierPath()
var start: CGPoint = CGPointMake(point.x + radius, point.y)
circle.moveToPoint(start)
// It was not working with i=0...
// Do not know why
for (var i=0.0001; i {
let test = CGFloat( i * M_PI/180)
let cosTest = cos(test)
let sinTest = sin(test)
x = (point.x + radius * cosTest)
y = (point.y + radius * sinTest)
circle.addLineToPoint(CGPointMake(x, y))
}
circle.closePath()
circle.stroke()
I do not know if the error messages are because of the fact that I running the code in a Playground.