RoughSwift
RoughSwift allows us to easily make shapes in hand drawn, sketchy, comic style. Based on the same concept of Snowflake which generates CALayer
that are highly composable and changeable, RoughSwift turns drawing commands into beautiful sketchy graphics.
- [x] Support iOS, tvOS
- [ ] Support macOS
- [x] Support all shapes: line, rectangle, circle, ellipse, linear path, arc, curve, polygon, svg path
- [x] Generate
UIBezierPath
forCAShapeLayer
- [x] Easy cusomizations with Options
- [x] Easy composable APIs
- [x] Convenient draw functions
- [x] Platform independant APIs which can easily support new platforms
- [x] Test coverage
- [x] Immutable and type safe data structure
- [ ] SVG elliptical arc
There are Playground and Example project where you can explore further.
Basic
Use generator
in draw
function to specify which shape to render. The returned CALayer
contains the rendered result in correct size
and is updated everytime generator
is instructed.
Here's how to draw a green rectangle
The beauty of CALayer
is that we can further animate, transform (translate, scale, rotate) and compose them into more powerful shapes.
Options
Options
is used to custimize shape. It is immutable struct and apply to one shape at a time. The following properties are configurable
- maxRandomnessOffset
- toughness
- bowing
- fill
- stroke
- strokeWidth
- curveTightness
- curveStepCount
- fillStyle
- fillWeight
- hachureAngle
- hachureGap
- dashOffset
- dashGap
- zigzagOffset
Shapes
RoughSwift supports all primitive shapes, including SVG path
- line
- rectangle
- ellipse
- circle
- linearPath
- arc
- curve
- polygon
- path
Fill style
Most of the time, we use fill
for solid fill color inside shape, stroke
for shape border, and fillStyle
for sketchy fill style.
Available fill styles
- crossHatch
- dashed
- dots
- hachure
- solid
- starBurst
- zigzag
- zigzagLine
Here's how to draw circles in different fill styles. The default fill style is hachure
SVG
SVG shape can be bigger or smaller than the specifed layer size, so RoughSwift scales them to your requested size
. This way we can compose and transform the SVG shape.
Creative shapes
With all the primitive shapes, we can create more beautiful things. The only limit is your imagination.
Here's how to create chart
Advance with Drawable, Generator and Renderer
Behind the screen, draw
function composes Generator
and Renderer
. We don't really need to know this detail but it's good to know in case we want more fine grained control.
We can instantiate Engine
or use a shared Engine
for memory efficiency, to make Generator
. Every time we instruct Generator
to draw a shape, the engine works hard to figure out information about the sketchy shape in Drawable
.
The name of these concepts follow rough.js
for better code reasoning.
For iOS, there is a Renderer
that can handle Drawable
and transform it into UIBezierPath
and CALayer
. There will be more Renderer
that can render into graphics context, image and for other platforms like macOS and watchOS.
Installation
RoughSwift is available through CocoaPods. To install
it, simply add the following line to your Podfile:
RoughSwift is also available through Carthage.
To install just write into your Cartfile:
RoughSwift can also be installed manually. Just download and drop Sources
folders in your project.