Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/davidcairns/DePict
A simple, declarative, functional drawing framework, in Swift!
https://github.com/davidcairns/DePict
Last synced: 8 days ago
JSON representation
A simple, declarative, functional drawing framework, in Swift!
- Host: GitHub
- URL: https://github.com/davidcairns/DePict
- Owner: davidcairns
- License: mit
- Created: 2015-03-25T08:26:51.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2016-11-07T15:38:10.000Z (about 8 years ago)
- Last Synced: 2024-08-14T14:06:25.665Z (4 months ago)
- Language: Swift
- Size: 46.9 KB
- Stars: 36
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-ios - DePict - A simple, declarative, functional drawing framework, in Swift! (Graphics / Getting Started)
- awesome-ios-star - DePict - A simple, declarative, functional drawing framework, in Swift! (Graphics / Getting Started)
- awesome-swift-cn - DePict - functional wrapper for CoreGraphics. (Libs / Images)
README
# DePict - A simple, declarative, functional drawing framework.
To produce a drawing, call the `Draw` function (just type *Draw* and let autocomplete
do the rest!).Pass `Draw` a `Colorer`. There are currently two ways to color something. Type either:
• *Filled*, for filled-in shapes, or
• *Outlined*, for outlined or “stroked” shapes.And then provide a color -- `Black`, `Yellow`, `Red`, or create anything you like.
Now you can specify the `Shape` to be drawn:
• `Line`
• `Rectangle`
• `Circle`
• & moreThe end result of this is that your code reads like the thing you're actually drawing:
`Draw(colorer: Filled(color: Blue, shape: Circle(…)))`
“Draw a Filled Blue Circle”-----
### Drawing a Face
We can draw a face in just a single line of readable, declarative code. See how the pieces reflect the final result.
```
Draw(colorer:
// Hair (behind head)
Filled(color: Black, shape: Circle(centerX: 50, Y: 58, radius: 40))
// Face
+ Filled(color: Brown, shape: Circle(centerX: 50, Y: 50, radius: 40))
// Eyes and pupils
+ Filled(color: White, shape: Rectangle(x: 20, y: 50, width: 20, height: 8))
+ Filled(color: Blue, shape: Circle(centerX: 30, Y: 54, radius: 2))
+ Filled(color: White, shape: Rectangle(x: 60, y: 50, width: 20, height: 8))
+ Filled(color: Blue, shape: Circle(centerX: 70, Y: 54, radius: 2))
// Nose
+ Outlined(color: Light(Brown), shape:
Line(fromX: 50, y: 54, toX: 56, y: 44)
+ Line(fromX: 56, y: 44, toX: 52, y: 42)
)
// Mouth
+ Outlined(color: Light(Red), shape:
Line([(40, 30), (46, 25), (54, 25)])
)
)
```![A Face](http://davidcairns.github.io/DePict_README_images/face.png "A Face")
### Drawing Information graphics
It’s trivial to use DePict to turn data into information graphics, and the declarative style allows you to do so in an obvious, clear way.
1) Start with some data you want to graph…
`let data = [11, 87, 98, 48, 41, 88, 63, 69, 8, 79]`2) For each datum, create a filled rectangle with height relative to its value.
`let bars = Array(0 ..< data.count).map({ Filled(color: Magenta, shape: Rectangle(x: $0 * 10, y: 0, width: 5, height: data[$0])) })`3) Combine the rectangles.
`let graphData = bars.reduce(EmptyColorer(), combine: +)`![Bar Charts](http://davidcairns.github.io/DePict_README_images/bar-chart.png "A Bar Chart")
-----
DePict is a super-simple wrapper for CoreGraphics that makes your drawing easy to ready and modify. It works great for iOS and Mac apps. Anything you would use CoreGraphics for, you can express more simply and easily with DePict.
If you come up with something fun, fork the code, or tweet me `@davidcairns`!