Created
April 18, 2017 06:05
-
-
Save yuhao-git-star/3d3915bf1372caac1e43b569cbc38f47 to your computer and use it in GitHub Desktop.
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
class CircleView : UIView { | |
override func draw(_ rect: CGRect) { | |
let 畫筆 = UIBezierPath() | |
畫筆.move(to: .zero) | |
// 畫筆.addLine(to: CGPoint(x: 100, y: 100)) | |
// x^2 + y^2 = r^2 | |
// cos(θ) = x/r ==> x = r * cos(θ) | |
// sin(θ) = y/r == y = r * sin(θ) | |
let radius:Double = 100 | |
for i in stride(from: 0, to: 180, by: 10){ | |
let x = radius * cos(Double(i)) | |
let y = radius * sin(Double(i)) | |
畫筆.addLine(to: CGPoint(x: x, y: y)) | |
} | |
畫筆.stroke() | |
} | |
} | |
let view = CircleView(frame: CGRect(x: 0, y: 0, width: 300, height: 300)) | |
view.backgroundColor = UIColor.white |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment