Skip to content

Commit

Permalink
🫧:: 삼각형 코드 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
jjunhaa0211 committed Oct 4, 2023
1 parent a939807 commit 378afdb
Showing 1 changed file with 11 additions and 20 deletions.
31 changes: 11 additions & 20 deletions PContributionsView/Classes/PContributionsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -221,27 +221,18 @@ open class PContributionsView: UIView {
path.addLine(to: CGPoint(x: x.x, y: x.y))
path.close()
case .triangle:
let angle: CGFloat = .pi / 10
let radius: CGFloat = CGFloat(rectWidth) / 2
let centerX: CGFloat = (x.x + y.x) / 2
let centerY: CGFloat = (x.y + y.y) / 2

var shouldMove: Bool = true
var currentPoint = CGPoint.zero

for i in 0..<10 {
let radius = (i % 2 == 0) ? cornerRadius : cornerRadius / 2
let xVal = (radius * cos(angle * CGFloat(i))) + (x.x + y.x) / 2
let yVal = (radius * sin(angle * CGFloat(i))) + (x.y + y.y) / 2
let point = CGPoint(x: xVal, y: yVal)

if shouldMove {
path.move(to: point)
currentPoint = point
shouldMove = false
} else {
path.addLine(to: point)
}

currentPoint = point
}
let point1 = CGPoint(x: centerX, y: centerY - radius)
let point2 = CGPoint(x: centerX - radius * cos(.pi / 6), y: centerY + radius * sin(.pi / 6))
let point3 = CGPoint(x: centerX + radius * cos(.pi / 6), y: centerY + radius * sin(.pi / 6))

path.move(to: point1)
path.addLine(to: point2)
path.addLine(to: point3)
path.close()

case .pentagon: // 5각형 그리기
let radius: CGFloat = CGFloat(rectWidth / 2)
Expand Down

0 comments on commit 378afdb

Please sign in to comment.