運用 UIBezierPath 繪製一隻星際大戰八部曲裡可愛的Porg

這真的是磨練耐心的好作業啊~

自從看了《星際大戰八部曲:最後的絕地武士》(Star Wars Episode VIII: The Last Jedi)就深深愛上了戲裡面被稱作『Porgs』的小鳥,來看看影片裡那些水汪汪的大眼睛:

星際大戰-最後的絕地武士Porg的畫面片段

在想要畫什麼圖來當作UIBezierPath的練習時,第一個念頭就想到要來畫Porg,本來以為Porg的線條很簡單,沒想到我還是畫了一整天啊!最後的成品長得蠻像山寨版的Porg,要一模一樣就要花更多時間在研究座標上了:

Playground的Porg成品

原圖出處:

程式碼:

import UIKitimport PlaygroundSupportlet rect = CGRect(x: 0, y: 0, width: 1000, height: 1000)let backgroundView = UIView(frame: rect)backgroundView.backgroundColor = UIColor(red: 0/255, green: 0/255, blue: 0/255, alpha: 1)//最外邊輪廓形狀-白色let bigPath = UIBezierPath()bigPath.move(to: CGPoint(x: 90, y: 178))bigPath.addLine(to: CGPoint(x: 300, y: 530))bigPath.addLine(to: CGPoint(x: 160, y: 530))bigPath.addLine(to: CGPoint(x: 115, y: 620))bigPath.addLine(to: CGPoint(x: 350, y: 620))bigPath.addLine(to: CGPoint(x: 440, y: 770))bigPath.addLine(to: CGPoint(x: 780, y: 178))bigPath.addLine(to: CGPoint(x: 580, y: 178))//半圓形的部分bigPath.move(to: CGPoint(x: 580, y: 178))bigPath.addCurve(to: CGPoint(x: 290, y: 178),controlPoint1: CGPoint(x: 550, y: 5),controlPoint2: CGPoint(x: 320, y: 5))bigPath.close()let bigShapeLayer = CAShapeLayer()bigShapeLayer.path = bigPath.cgPathlet bigView = UIView(frame: CGRect(x: 0, y: 0, width: 1000, height: 1000))bigView.backgroundColor = UIColor(red: 255, green: 255, blue:255, alpha: 1)bigView.layer.mask = bigShapeLayer//第二個三角形-黑色let secondPath = UIBezierPath()secondPath.move(to: CGPoint(x: 120, y: 195))secondPath.addLine(to: CGPoint(x: 755, y: 195))secondPath.addLine(to: CGPoint(x: 440, y: 740))secondPath.close()let secondShapeLayer = CAShapeLayer()secondShapeLayer.path = secondPath.cgPathlet secondView = UIView(frame: CGRect(x: 0, y: 0, width: 1000, height: 1000))secondView.backgroundColor = UIColor(red: 0/255, green: 0/255, blue:0/255, alpha: 1)secondView.layer.mask = secondShapeLayer//第三個三角形-黃色let thirdPath = UIBezierPath()thirdPath.move(to: CGPoint(x: 135, y: 205))thirdPath.addLine(to: CGPoint(x: 735, y: 205))thirdPath.addLine(to: CGPoint(x: 440, y: 720))thirdPath.close()let thirdShapeLayer = CAShapeLayer()thirdShapeLayer.path = thirdPath.cgPathlet thirdView = UIView(frame: CGRect(x: 0, y: 0, width: 1000, height: 1000))thirdView.backgroundColor = UIColor(red: 255/255, green: 191/255, blue:0/255, alpha: 1)thirdView.layer.mask = thirdShapeLayer//身體let bodyPath = UIBezierPath()bodyPath.move(to: CGPoint(x: 370, y: 250))bodyPath.addCurve(to: CGPoint(x: 500, y: 250),controlPoint1: CGPoint(x: 130, y: 640),controlPoint2: CGPoint(x: 750, y: 640))bodyPath.close()let bodyShapeLayer = CAShapeLayer()bodyShapeLayer.path = bodyPath.cgPathlet bodyView = UIView(frame: CGRect(x: 0, y: 0, width: 1000, height: 1000))bodyView.backgroundColor = UIColor(red: 255, green: 255, blue: 255, alpha: 1)bodyView.layer.mask = bodyShapeLayerlet outlinebodyPath = UIBezierPath()outlinebodyPath.move(to: CGPoint(x: 360, y: 250))outlinebodyPath.addCurve(to: CGPoint(x: 510, y: 250),controlPoint1: CGPoint(x: 130, y: 650),controlPoint2: CGPoint(x: 750, y: 650))outlinebodyPath.close()let outlinebodyShapeLayer = CAShapeLayer()outlinebodyShapeLayer.path = outlinebodyPath.cgPathlet outlinebodyView = UIView(frame: CGRect(x: 0, y: 0, width: 1000, height: 1000))outlinebodyView.backgroundColor = UIColor(red: 0/255, green: 0/255, blue: 0/255, alpha: 1)outlinebodyView.layer.mask = outlinebodyShapeLayer//左手let lhandPath = UIBezierPath()lhandPath.move(to: CGPoint(x: 330, y: 250))lhandPath.addCurve(to: CGPoint(x: 360, y: 250),controlPoint1: CGPoint(x: 200, y: 550),controlPoint2: CGPoint(x: 300, y: 550))lhandPath.close()let lhandShapeLayer = CAShapeLayer()lhandShapeLayer.path = lhandPath.cgPathlet lhandView = UIView(frame: CGRect(x: 0, y: 0, width: 1000, height: 1000))lhandView.backgroundColor = UIColor(red: 0/255, green: 0/255, blue: 0/255, alpha: 1)lhandView.layer.mask = lhandShapeLayer//右手let rhandPath = UIBezierPath()rhandPath.move(to: CGPoint(x: 545, y: 250))rhandPath.addCurve(to: CGPoint(x: 520, y: 250),controlPoint1: CGPoint(x: 670, y: 550),controlPoint2: CGPoint(x: 550, y: 550))rhandPath.close()let rhandShapeLayer = CAShapeLayer()rhandShapeLayer.path = rhandPath.cgPathlet rhandView = UIView(frame: CGRect(x: 0, y: 0, width: 1000, height: 1000))rhandView.backgroundColor = UIColor(red: 0/255, green: 0/255, blue: 0/255, alpha: 1)rhandView.layer.mask = rhandShapeLayer//頭-黑色let headPath = UIBezierPath()headPath.move(to: CGPoint(x: 565, y: 195))headPath.addCurve(to: CGPoint(x: 305, y: 195),controlPoint1: CGPoint(x: 550, y: 20),controlPoint2: CGPoint(x: 320, y: 20))headPath.move(to: CGPoint(x: 305, y: 195))headPath.addLine(to: CGPoint(x: 290, y: 270))//1headPath.addLine(to: CGPoint(x: 300, y: 270))//2headPath.addLine(to: CGPoint(x: 310, y: 283))//3headPath.addLine(to: CGPoint(x: 325, y: 270))//4headPath.addLine(to: CGPoint(x: 330, y: 285))//5headPath.addLine(to: CGPoint(x: 340, y: 280))//6headPath.addLine(to: CGPoint(x: 345, y: 290))//7headPath.addLine(to: CGPoint(x: 360, y: 280))//8headPath.addLine(to: CGPoint(x: 370, y: 295))//9headPath.addLine(to: CGPoint(x: 385, y: 287))//10headPath.addLine(to: CGPoint(x: 400, y: 300))//11headPath.addLine(to: CGPoint(x: 415, y: 280))//12headPath.addLine(to: CGPoint(x: 435, y: 305))//13headPath.addLine(to: CGPoint(x: 455, y: 280))//14headPath.addLine(to: CGPoint(x: 470, y: 300))//15headPath.addLine(to: CGPoint(x: 490, y: 285))//16headPath.addLine(to: CGPoint(x: 500, y: 298))//17headPath.addLine(to: CGPoint(x: 515, y: 285))//18headPath.addLine(to: CGPoint(x: 528, y: 290))//19headPath.addLine(to: CGPoint(x: 538, y: 275))//20headPath.addLine(to: CGPoint(x: 550, y: 290))//21headPath.addLine(to: CGPoint(x: 558, y: 278))//22headPath.addLine(to: CGPoint(x: 565, y: 285))//23headPath.addLine(to: CGPoint(x: 575, y: 270))//24headPath.addLine(to: CGPoint(x: 585, y: 265))//25headPath.addLine(to: CGPoint(x: 565, y: 195))//26headPath.close()let headShapeLayer = CAShapeLayer()headShapeLayer.path = headPath.cgPathlet headView = UIView(frame: CGRect(x: 0, y: 0, width: 1000, height: 1000))headView.backgroundColor = UIColor(red: 0/255, green: 0/255, blue:0/255, alpha: 1)headView.layer.mask = headShapeLayer//臉-白色let facePath = UIBezierPath()facePath.move(to: CGPoint(x: 515, y: 140))facePath.addCurve(to: CGPoint(x: 355, y: 140),controlPoint1: CGPoint(x: 480, y: 60),controlPoint2: CGPoint(x: 400, y: 60))facePath.move(to: CGPoint(x: 355, y: 140))facePath.addLine(to: CGPoint(x: 305, y: 235))//左鬚facePath.addLine(to: CGPoint(x: 326, y: 215))//1facePath.addLine(to: CGPoint(x: 305, y: 260))//2facePath.addLine(to: CGPoint(x: 310, y: 277))//3facePath.addLine(to: CGPoint(x: 325, y: 264))//4facePath.addLine(to: CGPoint(x: 330, y: 278))//5facePath.addLine(to: CGPoint(x: 340, y: 274))//6facePath.addLine(to: CGPoint(x: 345, y: 284))//7facePath.addLine(to: CGPoint(x: 360, y: 274))//8facePath.addLine(to: CGPoint(x: 370, y: 289))//9facePath.addLine(to: CGPoint(x: 385, y: 281))//10facePath.addLine(to: CGPoint(x: 400, y: 294))//11facePath.addLine(to: CGPoint(x: 415, y: 274))//12facePath.addLine(to: CGPoint(x: 435, y: 299))//13facePath.addLine(to: CGPoint(x: 455, y: 274))//14facePath.addLine(to: CGPoint(x: 470, y: 294))//15facePath.addLine(to: CGPoint(x: 490, y: 279))//16facePath.addLine(to: CGPoint(x: 500, y: 292))//17facePath.addLine(to: CGPoint(x: 515, y: 279))//18facePath.addLine(to: CGPoint(x: 525, y: 284))//19facePath.addLine(to: CGPoint(x: 538, y: 269))//20facePath.addLine(to: CGPoint(x: 550, y: 284))//21facePath.addLine(to: CGPoint(x: 555, y: 269))//22facePath.addLine(to: CGPoint(x: 565, y: 279))//23facePath.addLine(to: CGPoint(x: 570, y: 264))//24facePath.addLine(to: CGPoint(x: 546, y: 211))//25facePath.addLine(to: CGPoint(x: 566, y: 236))//右鬚1facePath.addLine(to: CGPoint(x: 515, y: 140))//右鬚2facePath.close()let faceShapeLayer = CAShapeLayer()faceShapeLayer.path = facePath.cgPathlet faceView = UIView(frame: CGRect(x: 0, y: 0, width: 1000, height: 1000))faceView.backgroundColor = UIColor(red: 255, green: 255, blue:255, alpha: 1)faceView.layer.mask = faceShapeLayer//眼框let eyesPath = UIBezierPath()//右眼框eyesPath.move(to: CGPoint(x: 515, y: 140))eyesPath.addQuadCurve(to: CGPoint(x: 450, y: 90), controlPoint: CGPoint(x: 525, y: 70))eyesPath.close()//左眼框eyesPath.move(to: CGPoint(x: 355, y: 140))eyesPath.addQuadCurve(to: CGPoint(x: 420, y: 90), controlPoint: CGPoint(x: 355, y: 70))eyesPath.close()let eyesShapeLayer = CAShapeLayer()eyesShapeLayer.path = eyesPath.cgPathlet eyesView = UIView(frame: CGRect(x: 0, y: 0, width: 1000, height: 1000))eyesView.backgroundColor = UIColor(red: 255, green: 255, blue: 255, alpha: 1)eyesView.layer.mask = eyesShapeLayer//眼球//右眼球let eyeballrPath = UIBezierPath(ovalIn: CGRect(x: 465, y: 95, width: 45, height: 50))let eyeballrShapeLayer = CAShapeLayer()eyeballrShapeLayer.path = eyeballrPath.cgPathlet eyeballrView = UIView(frame: CGRect(x: 0, y: 0, width: 1000, height: 1000))eyeballrView.backgroundColor = UIColor(red: 0/255, green: 0/255, blue: 0/255, alpha: 1)eyeballrView.layer.mask = eyeballrShapeLayer//左眼球let eyeballlPath = UIBezierPath(ovalIn: CGRect(x: 365, y: 95, width: 45, height: 50))let eyeballlShapeLayer = CAShapeLayer()eyeballlShapeLayer.path = eyeballlPath.cgPathlet eyeballlView = UIView(frame: CGRect(x: 0, y: 0, width: 1000, height: 1000))eyeballlView.backgroundColor = UIColor(red: 0/255, green: 0/255, blue: 0/255, alpha: 1)eyeballlView.layer.mask = eyeballlShapeLayer//瞳孔//右瞳孔let pupilrPath = UIBezierPath(ovalIn: CGRect(x: 480, y: 100, width: 10, height: 10))let pupilrShapeLayer = CAShapeLayer()pupilrShapeLayer.path = pupilrPath.cgPathlet pupilrView = UIView(frame: CGRect(x: 0, y: 0, width: 1000, height: 1000))pupilrView.backgroundColor = UIColor(red: 255, green: 255, blue: 255, alpha: 1)pupilrView.layer.mask = pupilrShapeLayer//左曈孔let pupillPath = UIBezierPath(ovalIn: CGRect(x: 380, y: 100, width: 10, height: 10))let pupillShapeLayer = CAShapeLayer()pupillShapeLayer.path = pupillPath.cgPathlet pupillView = UIView(frame: CGRect(x: 0, y: 0, width: 1000, height: 1000))pupillView.backgroundColor = UIColor(red: 255, green: 255, blue: 255, alpha: 1)pupillView.layer.mask = pupillShapeLayer//嘴巴let mouthPath = UIBezierPath()mouthPath.move(to: CGPoint(x: 470, y: 170))mouthPath.addQuadCurve(to: CGPoint(x: 400, y: 170), controlPoint: CGPoint(x: 435, y: 120))mouthPath.addQuadCurve(to: CGPoint(x: 470, y: 170), controlPoint: CGPoint(x: 435, y: 130))mouthPath.close()let mouthShapeLayer = CAShapeLayer()mouthShapeLayer.path = mouthPath.cgPathlet mouthView = UIView(frame: CGRect(x: 0, y: 0, width: 1000, height: 1000))mouthView.backgroundColor = UIColor(red: 0/255, green: 0/255, blue:0/255, alpha: 1)mouthView.layer.mask = mouthShapeLayer//鼻子let nosePath = UIBezierPath()//右鼻孔nosePath.move(to: CGPoint(x: 460, y: 140))nosePath.addQuadCurve(to: CGPoint(x: 440, y: 142), controlPoint: CGPoint(x: 450, y: 130))nosePath.addQuadCurve(to: CGPoint(x: 460, y: 140), controlPoint: CGPoint(x: 450, y: 140))nosePath.close()//左鼻孔nosePath.move(to: CGPoint(x: 410, y: 140))nosePath.addQuadCurve(to: CGPoint(x: 430, y: 142), controlPoint: CGPoint(x: 420, y: 130))nosePath.addQuadCurve(to: CGPoint(x: 410, y: 140), controlPoint: CGPoint(x: 420, y: 140))nosePath.close()let noseShapeLayer = CAShapeLayer()noseShapeLayer.path = nosePath.cgPathlet noseView = UIView(frame: CGRect(x: 0, y: 0, width: 1000, height: 1000))noseView.backgroundColor = UIColor(red: 0/255, green: 0/255, blue:0/255, alpha: 1)noseView.layer.mask = noseShapeLayer//左腳let lfootPath = UIBezierPath()lfootPath.move(to: CGPoint(x: 375, y: 520))lfootPath.addLine(to: CGPoint(x: 365, y: 565))lfootPath.addLine(to: CGPoint(x: 300, y: 565))lfootPath.addLine(to: CGPoint(x: 290, y: 580))lfootPath.addLine(to: CGPoint(x: 405, y: 580))lfootPath.addLine(to: CGPoint(x: 395, y: 565))lfootPath.addLine(to: CGPoint(x: 405, y: 520))lfootPath.close()let lfootShapeLayer = CAShapeLayer()lfootShapeLayer.path = lfootPath.cgPathlet lfootView = UIView(frame: CGRect(x: 0, y: 0, width: 1000, height: 1000))lfootView.backgroundColor = UIColor(red: 255, green: 255, blue: 255, alpha: 1)lfootView.layer.mask = lfootShapeLayerlet linelfootPath = UIBezierPath()linelfootPath.move(to: CGPoint(x: 370, y: 520))linelfootPath.addLine(to: CGPoint(x: 360, y: 560))linelfootPath.addLine(to: CGPoint(x: 300, y: 560))linelfootPath.addLine(to: CGPoint(x: 285, y: 585))linelfootPath.addLine(to: CGPoint(x: 415, y: 585))linelfootPath.addLine(to: CGPoint(x: 400, y: 565))linelfootPath.addLine(to: CGPoint(x: 410, y: 520))linelfootPath.close()let linelfootShapeLayer = CAShapeLayer()linelfootShapeLayer.path = linelfootPath.cgPathlet linelfootView = UIView(frame: CGRect(x: 0, y: 0, width: 1000, height: 1000))linelfootView.backgroundColor = UIColor(red: 0/255, green: 0/255, blue: 0/255, alpha: 1)linelfootView.layer.mask = linelfootShapeLayer//右腳let rfootPath = UIBezierPath()rfootPath.move(to: CGPoint(x: 485, y: 520))rfootPath.addLine(to: CGPoint(x: 495, y: 565))rfootPath.addLine(to: CGPoint(x: 550, y: 565))rfootPath.addLine(to: CGPoint(x: 560, y: 580))rfootPath.addLine(to: CGPoint(x: 465, y: 580))rfootPath.addLine(to: CGPoint(x: 470, y: 565))rfootPath.addLine(to: CGPoint(x: 460, y: 520))rfootPath.close()let rfootShapeLayer = CAShapeLayer()rfootShapeLayer.path = rfootPath.cgPathlet rfootView = UIView(frame: CGRect(x: 0, y: 0, width: 1000, height: 1000))rfootView.backgroundColor = UIColor(red: 255, green: 255, blue: 255, alpha: 1)rfootView.layer.mask = rfootShapeLayerlet linerfootPath = UIBezierPath()linerfootPath.move(to: CGPoint(x: 490, y: 520))linerfootPath.addLine(to: CGPoint(x: 500, y: 560))linerfootPath.addLine(to: CGPoint(x: 555, y: 560))linerfootPath.addLine(to: CGPoint(x: 570, y: 585))linerfootPath.addLine(to: CGPoint(x: 455, y: 585))linerfootPath.addLine(to: CGPoint(x: 465, y: 565))linerfootPath.addLine(to: CGPoint(x: 455, y: 520))linerfootPath.close()let linerfootShapeLayer = CAShapeLayer()linerfootShapeLayer.path = linerfootPath.cgPathlet linerfootView = UIView(frame: CGRect(x: 0, y: 0, width: 1000, height: 1000))linerfootView.backgroundColor = UIColor(red: 0/255, green: 0/255, blue: 0/255, alpha: 1)linerfootView.layer.mask = linerfootShapeLayer//球棒let stickPath = UIBezierPath()stickPath.move(to: CGPoint(x: 320, y: 560))stickPath.addLine(to: CGPoint(x: 330, y: 560))stickPath.addLine(to: CGPoint(x: 693, y: 188))stickPath.addLine(to: CGPoint(x: 700, y: 200))stickPath.addLine(to: CGPoint(x: 330, y: 590))stickPath.addLine(to: CGPoint(x: 300, y: 590))stickPath.close()let stickShapeLayer = CAShapeLayer()stickShapeLayer.path = stickPath.cgPathlet stickView = UIView(frame: CGRect(x: 0, y: 0, width: 1000, height: 1000))stickView.backgroundColor = UIColor(red: 255, green: 255, blue: 255, alpha: 1)stickView.layer.mask = stickShapeLayerlet linestickPath = UIBezierPath()linestickPath.move(to: CGPoint(x: 320, y: 557))linestickPath.addLine(to: CGPoint(x: 330, y: 557))linestickPath.addLine(to: CGPoint(x: 690, y: 185))linestickPath.addLine(to: CGPoint(x: 700, y: 190))linestickPath.addLine(to: CGPoint(x: 330, y: 595))linestickPath.addLine(to: CGPoint(x: 300, y: 595))linestickPath.close()let linestickShapeLayer = CAShapeLayer()linestickShapeLayer.path = linestickPath.cgPathlet linestickView = UIView(frame: CGRect(x: 0, y: 0, width: 1000, height: 1000))linestickView.backgroundColor = UIColor(red: 0/255, green: 0/255, blue: 0/255, alpha: 1)linestickView.layer.mask = linestickShapeLayer//球棒矩形let plankPath = UIBezierPath()plankPath.move(to: CGPoint(x: 175, y: 550))plankPath.addLine(to: CGPoint(x: 325, y: 550))plankPath.addLine(to: CGPoint(x: 300, y: 600))plankPath.addLine(to: CGPoint(x: 148, y: 600))plankPath.close()let plankShapeLayer = CAShapeLayer()plankShapeLayer.path = plankPath.cgPathlet plankView = UIView(frame: CGRect(x: 0, y: 0, width: 1000, height: 1000))plankView.backgroundColor = UIColor(red: 0/255, green: 0/255, blue: 0/255, alpha: 1)plankView.layer.mask = plankShapeLayer//擊球處let splankPath = UIBezierPath()splankPath.move(to: CGPoint(x: 178, y: 555))splankPath.addLine(to: CGPoint(x: 202, y: 555))splankPath.addLine(to: CGPoint(x: 182, y: 595))splankPath.addLine(to: CGPoint(x: 157, y: 595))splankPath.close()let splankShapeLayer = CAShapeLayer()splankShapeLayer.path = splankPath.cgPathlet splankView = UIView(frame: CGRect(x: 0, y: 0, width: 1000, height: 1000))splankView.backgroundColor = UIColor(red: 255, green: 255, blue:255, alpha: 1)splankView.layer.mask = splankShapeLayer//圖層疊圖backgroundView.addSubview(bigView)backgroundView.addSubview(secondView)backgroundView.addSubview(thirdView)backgroundView.addSubview(linelfootView)backgroundView.addSubview(lfootView)backgroundView.addSubview(linerfootView)backgroundView.addSubview(rfootView)backgroundView.addSubview(outlinebodyView)backgroundView.addSubview(bodyView)backgroundView.addSubview(lhandView)backgroundView.addSubview(rhandView)backgroundView.addSubview(headView)backgroundView.addSubview(faceView)backgroundView.addSubview(eyesView)backgroundView.addSubview(eyeballrView)backgroundView.addSubview(eyeballlView)backgroundView.addSubview(pupilrView)backgroundView.addSubview(pupillView)backgroundView.addSubview(mouthView)backgroundView.addSubview(noseView)//backgroundView.addSubview(linestickView)backgroundView.addSubview(stickView)backgroundView.addSubview(plankView)backgroundView.addSubview(splankView)PlaygroundPage.current.liveView = backgroundView

關於圖案的輪廓,上方程式碼是用疊圖的方式疊出圖案的黑色框線,但這樣做蠻浪費時間的,請教了小王子(Peter)之後,才知道還有一個比較省時的方法,運用addSublayer去描出圖案的框線,在這邊先拿球棒的部分試試,真的快很多,畫出來的框線也比較精準:

運用addSublayer較省時,也比較精確

程式碼:

//球棒
//球棒本體
let stickPath = UIBezierPath()stickPath.move(to: CGPoint(x: 320, y: 560))stickPath.addLine(to: CGPoint(x: 330, y: 560))stickPath.addLine(to: CGPoint(x: 693, y: 188))stickPath.addLine(to: CGPoint(x: 700, y: 200))stickPath.addLine(to: CGPoint(x: 330, y: 590))stickPath.addLine(to: CGPoint(x: 300, y: 590))stickPath.close()let stickShapeLayer = CAShapeLayer()stickShapeLayer.path = stickPath.cgPathlet stickView = UIView(frame: CGRect(x: 0, y: 0, width: 1000, height: 1000))stickView.backgroundColor = UIColor(red: 255, green: 255, blue: 255, alpha: 1)stickView.layer.mask = stickShapeLayer//球棒的黑色框線let linestickShapeLayer = CAShapeLayer()linestickShapeLayer.path = stickPath.cgPathlinestickShapeLayer.strokeColor = UIColor(red: 0/255, green: 0/255, blue: 0/255, alpha: 1).cgColorlinestickShapeLayer.lineWidth = 10linestickShapeLayer.fillColor = UIColor.clear.cgColorstickView.layer.addSublayer(linestickShapeLayer)backgroundView.addSubview(stickView)

附上GitHub

參考文章:

在開始畫之前還研究了一下貝茲曲線的運用,參考了這篇文章:

http://www.flycan.com/article/photoshop/photoshop-pen-tool-348.html

最後完成圖案真的蠻有成就感的,大家快來試試吧!

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Julia Wang

Julia Wang

Learning Programming , Hiking , Travels , Tour , Exploring nature 『你必須要很努力,才能看起來毫不費力』