要运行示例项目,请克隆存储库,然后首先从 Example 目录运行 pod install
。
SwiftCubicSpline 可通过 CocoaPods 获取。要安装它,只需将以下行添加到您的 Podfile
pod "SwiftCubicSpline"
let spline = CubicSpline(points: [
Point(x: 0.0, y: 0.5),
Point(x: 0.1, y: 0.5),
Point(x: 0.2, y: 0.7),
Point(x: 0.4, y: 0.3),
Point(x: 0.6, y: 0.6),
Point(x: 0.8, y: 0.4),
Point(x: 0.9, y: 0.5),
Point(x: 1.0, y: 0.5)
])
let graphSize = self.bounds.size
for y in 0 ..< Int(graphSize.height) {
let y = Double(y)
let x = spline[x: y/Double(graphSize.height)] * Double(graphSize.width)
if y == 0 {
context.move(to: CGPoint(x: x, y: y))
} else {
context.addLine(to: CGPoint(x: x, y: y))
}
}
context.strokePath()
giordano scalzo, giordano.scalzo@gmail.com
基于 SAMCubicSpline 和 CubicSpline
SwiftCubicSpline 在 MIT 许可下可用。有关更多信息,请参见 LICENSE 文件。