Skip to content

Instantly share code, notes, and snippets.

@alexnikol
alexnikol / .swift
Created June 16, 2020 14:35
Cuphead-EyesAndNoseShapes
private func getRightEyeShape() -> CAShapeLayer {
let rightEyeWrapPath = UIBezierPath()
rightEyeWrapPath.move(to: CGPoint(x: 392, y: 165))
rightEyeWrapPath.addCurve(to: CGPoint(x: 317, y: 175),
controlPoint1: CGPoint(x: 400, y: 200),
controlPoint2: CGPoint(x: 330, y: 230))
let eyePath = UIBezierPath()
eyePath.move(to: CGPoint(x: 345, y: 135))
eyePath.addQuadCurve(to: CGPoint(x: 350, y: 155),
controlPoint: CGPoint(x: 320, y: 150))
@alexnikol
alexnikol / .swift
Created June 16, 2020 14:17
Cuphead-MouthShape
private func getMouthShape() -> CAShapeLayer {
let path = UIBezierPath()
path.move(to: CGPoint(x: 310, y: 250))
path.addCurve(to: CGPoint(x: 175, y: 250),
controlPoint1: CGPoint(x: 330, y: 335),
controlPoint2: CGPoint(x: 125, y: 325))
path.addCurve(to: CGPoint(x: 310, y: 250),
controlPoint1: CGPoint(x: 195, y: 245),
controlPoint2: CGPoint(x: 260, y: 265))
let mouthShape = CAShapeLayer()
@alexnikol
alexnikol / .swift
Created June 16, 2020 14:14
Cuphead-HeadShape
private func getHeadShape() -> CAShapeLayer {
let path = UIBezierPath()
path.move(to: CGPoint(x: 84, y: 196)) //Set StartPoint for QuadCurve
path.addQuadCurve(to: CGPoint(x: 366, y: 100), //Add EndPoint QuadCurve and StartPoint for Curve
controlPoint: CGPoint(x: 205, y: 100))
path.addCurve(to: CGPoint(x: 84, y: 196), //Add EndPoint for Curve
controlPoint1: CGPoint(x: 500, y: 330),
controlPoint2: CGPoint(x: 120, y: 430))
path.close() //Connect first point and last point of bezier path
let headShape = CAShapeLayer()
@alexnikol
alexnikol / .swift
Created June 16, 2020 13:47
CupheadView
//
// CupheadView.swift
// UIBezierPathLesson
//
// Created by Alexander Nikolaychuk on 12.06.2020.
// Copyright © 2020 AlexAlmostEngineer. All rights reserved.
//
import UIKit
@alexnikol
alexnikol / .swift
Created June 16, 2020 13:18
UIBezierPath-ReadyToUseShapes
//Paths Part
let rect = UIBezierPath(rect: CGRect(x: 50, y: 50, width: 50, height: 50))
let oval = UIBezierPath(ovalIn: CGRect(x: 120, y: 120, width: 100, height: 50))
let roundedRect = UIBezierPath(roundedRect: CGRect(x: 200, y: 200, width: 50, height: 50),
cornerRadius: 10.0)
//Shapes
let rectShape = CAShapeLayer()
rectShape.path = rect.cgPath
rectShape.lineWidth = 4.0
rectShape.fillColor = UIColor.clear.cgColor
@alexnikol
alexnikol / .swift
Created June 16, 2020 13:07
UIBezierPath-Curve
//Path Part
let path = UIBezierPath()
path.move(to: CGPoint(x: 50, y: 200))
path.addCurve(to: CGPoint(x: 200, y: 200),
controlPoint1: CGPoint(x: 80, y: 300),
controlPoint2: CGPoint(x: 150, y: 0))
//Shape Part
let shape = CAShapeLayer()
shape.path = path.cgPath
shape.lineWidth = 4.0
@alexnikol
alexnikol / .swift
Last active June 16, 2020 13:08
UIBezierPath-QuadCurve
//Path part
let path = UIBezierPath()
path.move(to: CGPoint(x: 50, y: 50))
path.addQuadCurve(to: CGPoint(x: 200, y: 50),
controlPoint: CGPoint(x: 100, y: 200))
//Shape part
let shape = CAShapeLayer()
shape.path = path.cgPath
shape.lineWidth = 4.0
@alexnikol
alexnikol / .swift
Created June 16, 2020 12:21
UIBezierPath-Line
//Path part
let path = UIBezierPath()
path.move(to: CGPoint(x: 200, y: 200)) //StartPoint
path.addLine(to: CGPoint(x: 380, y: 380)) //EndPoint of First Line and StartPoint for Second Line
path.addLine(to: CGPoint(x: 20, y: 380)) //EndPoint of Second Line
//Shape part
let shape = CAShapeLayer()
shape.path = path.cgPath
shape.lineWidth = 4.0
@alexnikol
alexnikol / .swift
Last active June 11, 2020 08:47
Draw Segment Code
private func getSegment(startAngle: Radians,
endInAngle: Radians,
color: UIColor,
strokeEnd: CGFloat) -> CAShapeLayer {
let centre = CGPoint(x: bounds.width / 2, y: bounds.height / 2) //Center of drawing
let beizerPath = UIBezierPath(arcCenter: centre,
radius: bounds.height / 2 - settings.segmentWidth / 2, //Segment width
startAngle: startAngle, //Start angle in radians (0 for example)
endAngle: endInAngle, //End angle in radians (pi / 2 for example)
clockwise: true)
@alexnikol
alexnikol / .swift
Last active June 11, 2020 08:14
Full Multi-segment progress indicator
import UIKit
typealias Degrees = Double
typealias Radians = CGFloat
//Structure for custom indicator settings
struct ANSegmentIndicatorSettings {
var segmentsCount: Int = 4
var segmentWidth: CGFloat = 2
var spaceBetweenSegments: Degrees = 10