A simple, declarative, functional drawing framework, in Swift!

Related tags

Graphics DePict
Overview

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: • LineRectangleCircle • & more

The 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

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


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!

You might also like...
Conical (angular) gradient for iOS written in Swift
Conical (angular) gradient for iOS written in Swift

AEConicalGradient Conical (angular) gradient in Swift I hope that somebody will find this useful. And nice. Usage AEConicalGradient is a minion which

Powerful and easy-to-use vector graphics Swift library with SVG support
Powerful and easy-to-use vector graphics Swift library with SVG support

Macaw Powerful and easy-to-use vector graphics Swift library with SVG support We are a development agency building phenomenal apps. What is Macaw? Mac

Unique blocky identicons generator for Swift
Unique blocky identicons generator for Swift

⚗️ BlockiesSwift This library is a Swift implementation of the Ethereum fork of Blockies which is intended to be used in iOS, watchOS, tvOS and macOS

A lightweight XMLParser for assembling and parsing XML values written for iOS 8+ in Swift 2.
A lightweight XMLParser for assembling and parsing XML values written for iOS 8+ in Swift 2.

Overview Description Requirements Installation Usage Author License Description XMLParser lets you convert a pure Swift dictionary into XML string and

A simple, declarative, functional drawing framework, in Swift!
A simple, declarative, functional drawing framework, in Swift!

DePict - A simple, declarative, functional drawing framework. To produce a drawing, call the Draw function (just type Draw and let autocomplete do the

The application is develop in Objective IOS. kids can draw whatever they want and also kids can save the drawing as well as undo erase the drawing.
The application is develop in Objective IOS. kids can draw whatever they want and also kids can save the drawing as well as undo erase the drawing.

IOSObjC_KidsBoard The application is develop in Objective IOS. kids can draw whatever they want and also kids can save the drawing as well as undo era

Keep It Functional - An iOS Functional Testing Framework
Keep It Functional - An iOS Functional Testing Framework

IMPORTANT! Even though KIF is used to test your UI, you need to add it to your Unit Test target, not your UI Test target. The magic of KIF is that it

A SwiftUI Framework for Drawing Chart
A SwiftUI Framework for Drawing Chart

PrettyAxis A SwiftUI Framework for drawing charts. Fearture Support Drawing Bar Chart RadarChart Line Chart and Scatter Charts Pie Chart and Donut Cha

NXDrawKit is a simple and easy but useful drawing kit for iPhone
NXDrawKit is a simple and easy but useful drawing kit for iPhone

⚠️ To use with Swift 5.0 please ensure you are using = 0.8.0 ⚠️ ⚠️ To use with Swift 4.2 please ensure you are using = 0.7.1 ⚠️ ⚠️ To use with Swift

it's simple drawing app.
it's simple drawing app.

IOSObjC_KidsBoard The application is develop in Objective IOS. kids can draw whatever they want and also kids can save the drawing as well as undo era

it's simple drawing app
it's simple drawing app

IOSObjC_KidsBoard The application is develop in Objective IOS. kids can draw whatever they want and also kids can save the drawing as well as undo era

A simple drawing app for iPad using SwiftUI
A simple drawing app for iPad using SwiftUI

TinyDraw A small little drawing app fro iPad using SwiftUIs Canvas view. Implemented along the HWS+ live stream by Paul Hudson. Features Drawing lines

A Fast and Complete Swift Drawing Library

FastDraw A Fast and Complete Swift Drawing Library Description FastDraw is a high performance and highly extensible Drawing Library that supports Appl

Drawing and Geometry made easy on iOS - now in Swift 3.0

InkKit Swift Support Swift 4.0 InkKit is Swift 4.0 by default, so to use that just include InkKit in your podfile: pod 'InkKit' Swift 3.2 In order to

A Swift library for parsing and drawing SVG images to CoreGraphics contexts.

SwiftDraw A Swift library for parsing and drawing SVG images to CoreGraphics contexts. SwiftDraw can also convert an SVG into Swift source code. Usage

CoreMotion Controlled Drawing in 3D Space

SwiftSpace Gyroscope Driven Drawing in 3D Space Companion project to: http://flexmonkey.blogspot.co.uk/2015/08/coremotion-controlled-3d-sketching-on.h

PullToRefresh extension for all UIScrollView type classes with animated text drawing style
PullToRefresh extension for all UIScrollView type classes with animated text drawing style

PullToRefreshCoreText PullToRefresh extension for all UIScrollView type classes with animated text drawing style Demo Install Manual Copy the files in

iOS native app demo with Xcode and Swift using MVVM architecture and Apple's Combine framework for functional reactive programming, all with UIKit
iOS native app demo with Xcode and Swift using MVVM architecture and Apple's Combine framework for functional reactive programming, all with UIKit

iOS (Swift 5): MVVM test with Combine and UIKit MVVM and functional reactive programming (FRP) are very used in iOS development inside companies. Here

Functional DSP / Audio Framework for Swift

Lullaby Lullaby is an audio synthesis framework for Swift that supports both macOS and Linux! It was inspired by other audio environments like FAUST,

Owner
David Cairns
David Cairns
NXDrawKit is a simple and easy but useful drawing kit for iPhone

⚠️ To use with Swift 5.0 please ensure you are using >= 0.8.0 ⚠️ ⚠️ To use with Swift 4.2 please ensure you are using >= 0.7.1 ⚠️ ⚠️ To use with Swift

Nicejinux 1.3k Dec 31, 2022
it's simple drawing app.

IOSObjC_KidsBoard The application is develop in Objective IOS. kids can draw whatever they want and also kids can save the drawing as well as undo era

Vnnovate Solutions Pvt Ltd 0 Oct 28, 2021
it's simple drawing app

IOSObjC_KidsBoard The application is develop in Objective IOS. kids can draw whatever they want and also kids can save the drawing as well as undo era

Jiten Engineer 0 Oct 28, 2021
Drawing and Geometry made easy on iOS - now in Swift 3.0

InkKit Swift Support Swift 4.0 InkKit is Swift 4.0 by default, so to use that just include InkKit in your podfile: pod 'InkKit' Swift 3.2 In order to

Shaps 373 Dec 27, 2022
An iOS framework for easily adding drawings and text to images.

jot is an easy way to add touch-controlled drawings and text to images in your iOS app. What's jot for? Annotating Images jot is the easiest way to ad

IFTTT 1.8k Oct 28, 2022
A simple, performant, and lightweight SVG parser

Key Features Parsing performance that meets or beats other popular SVG Frameworks A simple architecture, optimized for extension, flexibility and deve

Michael Choe 1.8k Dec 29, 2022
🎞 Powerful gradient animations made simple for iOS.

AnimatedGradientView is a UIView subclass which makes it simple to add animated gradients to your iOS app. It is written purely in Swift. Further docu

Ross Butler 431 Dec 12, 2022
A simple game application for iPad using SpriteKit, SKCropNode

Whack-a-Penguin A simple game application for iPad using SpriteKit, SKCropNode,

NIKOLAY NIKITIN 1 Sep 12, 2022
QEMU-Manager is a macOS graphical frontend to QEMU, written in Swift.

QEMU-Manager About QEMU-Manager is a macOS graphical frontend to QEMU, written in Swift. Screenshots General Configuration: Hardware Configuration: Di

Jean-David Gadina 212 Jan 6, 2023
❄️ SVG in Swift

Snowflake ❤️ Support my apps ❤️ Push Hero - pure Swift native macOS application to test push notifications PastePal - Pasteboard, note and shortcut ma

Khoa 949 Dec 14, 2022