Skip to content

Instantly share code, notes, and snippets.

@alexnikol
Created Jun 16, 2020
Embed
What would you like to do?
Cuphead-EarAndDrinkingTube
private func getDrinkingTubeShape() -> CAShapeLayer {
//Wraper Shape
let wrapPath = UIBezierPath()
wrapPath.move(to: CGPoint(x: 170, y: 145))
wrapPath.addLine(to: CGPoint(x: 125, y: 70))
wrapPath.addLine(to: CGPoint(x: 5, y: 110))
wrapPath.addQuadCurve(to: CGPoint(x: 35, y: 175),
controlPoint: CGPoint(x: -5, y: 160))
wrapPath.addQuadCurve(to: CGPoint(x: 95, y: 150),
controlPoint: CGPoint(x: 60, y: 165))
wrapPath.addLine(to: CGPoint(x: 110, y: 175))
let tubeWrapShape = CAShapeLayer()
tubeWrapShape.path = wrapPath.cgPath
tubeWrapShape.lineWidth = 5
tubeWrapShape.strokeColor = UIColor.black.cgColor
tubeWrapShape.fillColor = UIColor.clear.cgColor
//Red Line 1
let redLinePath1 = UIBezierPath()
redLinePath1.move(to: CGPoint(x: 160, y: 130))
redLinePath1.addQuadCurve(to: CGPoint(x: 105, y: 170),
controlPoint: CGPoint(x: 120, y: 130))
redLinePath1.addCurve(to: CGPoint(x: 145, y: 105),
controlPoint1: CGPoint(x: 90, y: 140),
controlPoint2: CGPoint(x: 80, y: 120))
redLinePath1.close()
let redLineShape1 = CAShapeLayer()
redLineShape1.path = redLinePath1.cgPath
redLineShape1.lineWidth = 3
redLineShape1.strokeColor = UIColor.black.cgColor
redLineShape1.fillColor = UIColor(named: "orangeColor")?.cgColor
tubeWrapShape.addSublayer(redLineShape1)
//Red Line 2
let redLinePath2 = UIBezierPath()
redLinePath2.move(to: CGPoint(x: 70, y: 160))
redLinePath2.addLine(to: CGPoint(x: 70, y: 90))
redLinePath2.addLine(to: CGPoint(x: 40, y: 100))
redLinePath2.addLine(to: CGPoint(x: 40, y: 170))
redLinePath2.close()
let redLineShape2 = CAShapeLayer()
redLineShape2.path = redLinePath2.cgPath
redLineShape2.lineWidth = 3
redLineShape2.strokeColor = UIColor.black.cgColor
redLineShape2.fillColor = UIColor(named: "orangeColor")?.cgColor
tubeWrapShape.addSublayer(redLineShape2)
//Middle Line Shape
let middleLinePath = UIBezierPath()
middleLinePath.move(to: CGPoint(x: 97, y: 155))
middleLinePath.addQuadCurve(to: CGPoint(x: 125, y: 70),
controlPoint: CGPoint(x: 80, y: 80))
let middleLineShape = CAShapeLayer()
middleLineShape.path = middleLinePath.cgPath
middleLineShape.lineWidth = 3
middleLineShape.strokeColor = UIColor.black.cgColor
middleLineShape.fillColor = UIColor.clear.cgColor
tubeWrapShape.addSublayer(middleLineShape)
return tubeWrapShape
}
private func getEarShape() -> CAShapeLayer {
let path = UIBezierPath(arcCenter: CGPoint(x: 100, y: 260),
radius: 55.0,
startAngle: 1.4 * CGFloat.pi,
endAngle: CGFloat.pi / 4,
clockwise: false)
let path2 = UIBezierPath(arcCenter: CGPoint(x: 100, y: 260),
radius: 20.0,
startAngle: 1.4 * CGFloat.pi,
endAngle: CGFloat.pi / 4,
clockwise: false)
let earShape = CAShapeLayer()
earShape.path = path.cgPath
earShape.lineWidth = 5
earShape.strokeColor = UIColor.black.cgColor
earShape.fillColor = UIColor.clear.cgColor
let fullEar = CAShapeLayer()
fullEar.addSublayer(earShape)
let innerEar = CAShapeLayer()
innerEar.path = path2.cgPath
innerEar.lineWidth = 5
innerEar.strokeColor = UIColor.black.cgColor
innerEar.fillColor = UIColor.clear.cgColor
fullEar.addSublayer(innerEar)
return fullEar
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment