Rough 0.1.2

Rough 0.1.2

Bakhtiyor Khodjaev 维护。



Rough 0.1.2

  • 作者:
  • Bakhtiyor Khodjaev

Rough (Swift)

Version License Platform

Rough 允许您以草图风格、手绘风格绘画。它是对 Rough.js 的 Swift 模拟,该库定义了绘制线条、曲线、圆弧、多边形、圆和椭圆的原语。

要求

Xcode 9,iOS 9

安装

Rough 通过 CocoaPods 提供。要安装它,只需将以下行添加到您的 Podfile 中

pod 'Rough'

用法

Rectangle

let canvas = roughView.canvas
canvas.rectangle(origin: CGPoint(x: 10, y: 10), width: 200, height: 100)
roughView.setNeedsDisplay()

线和椭圆

Lines and Ellipses

canvas.circle(center: CGPoint(x: 80, y: 120), radius: 25)
canvas.ellipse(center: CGPoint(x: 300, y: 100), width: 150, height: 80)
canvas.line(from: CGPoint(x: 80, y: 120), to: CGPoint(x: 300, y: 100))

填充

Filling

canvas.circle(center: CGPoint(x: 50, y: 50), radius: 40) { options in
    options.fill = UIColor.red
} // fill with red hachure

canvas.rectangle(origin: CGPoint(x: 120, y: 15), width: 80, height: 80) { options in
    options.fill = UIColor.red
}

canvas.circle(center: CGPoint(x: 50, y: 150), radius: 40) {
    options in
    options.fill = UIColor(red: 10/255.0, green: 150/255.0, blue: 10/255.0, alpha: 1.0)
    options.fillWeight = 3 // thicker lines for hachure
}

canvas.rectangle(origin: CGPoint(x: 220, y: 15), width: 80, height: 80) { options in
    options.fill = UIColor.red
    options.hachureAngle = 60 // angle of hachure
    options.hachureGap = 8
}

canvas.rectangle(origin: CGPoint(x: 120, y: 105), width: 80, height: 80) { options in
    options.fill = UIColor(red: 1.0, green: 0, blue: 200/255.0, alpha: 0.2)
    options.fillStyle = .solid // solid fill
}

绘制风格

Sketching style

canvas.rectangle(origin: CGPoint(x: 15, y: 15), width: 80, height: 80) { options in
    options.roughness = 0.5
    options.fill = UIColor.red
}

canvas.rectangle(origin: CGPoint(x: 120, y: 15), width: 80, height: 80) { options in
    options.roughness = 2.8
    options.fill = UIColor.blue
}

canvas.rectangle(origin: CGPoint(x: 220, y: 15), width: 80, height: 80) { options in
    options.bowing = 6
    options.stroke = UIColor.green
    options.strokeWidth = 3
}

SVG路径

待办

示例

要运行示例项目,请先克隆仓库,然后从示例目录运行 pod install

Screenshot1 Screenshot2

致谢

感谢 Rough.js,由 Preet 创建

许可证

Rough 遵循 MIT 许可证。有关更多信息,请参阅 LICENSE 文件。