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

Related tags

Image 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...
DittoSwift - Swift package for the DittoSwift framework

DittoSwift Swift package for the DittoSwift framework. See the Ditto iOS Install

APNGKit is a high performance framework for loading and displaying APNG images in iOS and macOS.
APNGKit is a high performance framework for loading and displaying APNG images in iOS and macOS.

APNGKit is a high performance framework for loading and displaying APNG images in iOS and macOS. It's built on top of a modified version of libpng wit

SharkCardScan is a Credit/Debit Card scanner built using Apple's Vision Framework.
SharkCardScan is a Credit/Debit Card scanner built using Apple's Vision Framework.

iOS Credit/Debit card scanner, built using Apple's Vision Framework.

SwiftUI Image loading and Animation framework powered by SDWebImage
SwiftUI Image loading and Animation framework powered by SDWebImage

SDWebImageSwiftUI What's for SDWebImageSwiftUI is a SwiftUI image loading framework, which based on SDWebImage. It brings all your favorite features f

Swifttty and easy camera framework for iOS.
Swifttty and easy camera framework for iOS.

SwiftttCamera Swifttty and easy camera framework for iOS. View Demo · Report Bug · Request Feature SwiftttCamera is a wrapper around AVFoundation that

Utilizing Apple's Vision Framework to center faces in CGImage.
Utilizing Apple's Vision Framework to center faces in CGImage.

FaceCrop CGImage extension that utilizes Apple's Vision Framework to detect and center faces. Usage cgImage.faceCrop { [weak self] result in switc

An open source iOS framework for GPU-based image and video processing
An open source iOS framework for GPU-based image and video processing

GPUImage Brad Larson http://www.sunsetlakesoftware.com @bradlarson [email protected] Overview The GPUImage framework is a BSD-licensed iO

IOS UIImage processing functions using the vDSP/Accellerate framework for speed.

UIImage Image Processing extensions using the vDSP/Accelerate framework.

Advanced framework for loading, caching, processing, displaying and preheating images.
Advanced framework for loading, caching, processing, displaying and preheating images.

Advanced framework for loading, caching, processing, displaying and preheating images. This framework is no longer maintained. Programming in Swift? C

Owner
David Cairns
David Cairns
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

Simon Whitty 119 Jan 3, 2023
A simple macOS app to read code from images, written purely in Swift using Vision Framework.

CodeReader A simple macOS app to read code from images, written purely in Swift using Vision Framework. Usage Drag an image Click the convert button R

Md Ibrahim Hassan 44 Nov 20, 2022
A low-maintenance, simple framework for a snapshot testing, which takes into account a snapshot difference factor (must have if you're using CI).

CornSnapshotTesting A low-maintenance, simple framework for a snapshot testing, which takes into account a snapshot difference factor (must have if yo

Rita 2 Nov 29, 2021
Simple command-line utility for performing OCR using Apple's Vision framework

ocrit Runs Vision's OCR on input images and outputs corresponding txt files for each image, or writes the recognized results to standard output. USAGE

Guilherme Rambo 61 Nov 23, 2022
GPUImage 2 is a BSD-licensed Swift framework for GPU-accelerated video and image processing.

GPUImage 2 Brad Larson http://www.sunsetlakesoftware.com @bradlarson [email protected] Overview GPUImage 2 is the second generation of th

Brad Larson 4.8k Dec 29, 2022
GPUImage 3 is a BSD-licensed Swift framework for GPU-accelerated video and image processing using Metal.

GPUImage 3 Janie Clayton http://redqueengraphics.com @RedQueenCoder Brad Larson http://www.sunsetlakesoftware.com @bradlarson contact@sunsetlakesoftwa

Brad Larson 2.4k Jan 3, 2023
A pure Swift high-performance asynchronous image loading framework. SwiftUI supported.

Longinus Longinus is a pure-Swift high-performance asynchronous web image loading,caching,editing framework. It was learned from Objective-C web image

Qitao Yang 290 Dec 17, 2022
An image compositing framework written in Swift.

An asynchronous, multithreaded, image compositing framework written in Swift. Installation CocoaPods Add Overlay to your Podfile: pod 'OverlayComposit

Aaron Sutton 12 Dec 18, 2021
DOMKit - Swift framework to interact with the DOM in the browser

DOMKit Swift framework to interact with the DOM in the browser. Note: This proje

null 1 Jul 8, 2022
CameraEngine: The most advanced Camera framework in Swift

CameraEngine THIS REPOSITORY REFACTORED FROM ( https://github.com/remirobert/Cam

Mertcan Bulut 0 Jan 3, 2022