Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class MyDrawings: UIView {
- /*
- // Only override draw() if you perform custom drawing.
- // An empty implementation adversely affects performance during animation.
- override func draw(_ rect: CGRect) {
- // Drawing code
- }
- */
- override func draw(_ rect: CGRect) {
- let context=UIGraphicsGetCurrentContext()
- context?.setLineWidth(2.5)
- context?.setStrokeColor(UIColor.purple.cgColor)
- //drawTriangle(context: context,p1: CGPoint(x: 0, y: 0), p2: CGPoint(x: rect.width, y: rect.height/2), p3: CGPoint(x: rect.width/2, y: rect.height))
- var p1=CGPoint(x: rect.width/2, y: 10)
- var p2=CGPoint(x: 10, y: rect.height-10)
- var p3=CGPoint(x: rect.width-10, y: rect.height-10)
- for _ in 1...5 {
- context?.move(to: p1)
- context?.addLine(to: p2)
- context?.addLine(to: p3 )
- context?.addLine(to: p1)
- context?.strokePath()
- let temp = p1
- p1=mid(p1:p1,p2:p2)
- p2=mid(p1:p2,p2:p3)
- p3=mid(p1:p3, p2:temp)
- }
- }
- func mid(p1:CGPoint, p2:CGPoint) -> CGPoint {
- return CGPoint(x: (p1.x+p2.x)/2, y: (p1.y+p2.y)/2)
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement