Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Drawing with Code
Search
Ryan Nystrom
October 25, 2013
Programming
1
220
Drawing with Code
Drawing with Code - presented at M3 Conf (
http://m3conf.com
) 2013
Ryan Nystrom
October 25, 2013
Tweet
Share
More Decks by Ryan Nystrom
See All by Ryan Nystrom
Animation & Interaction Design
rnystrom
2
210
Facebook Pop
rnystrom
2
650
Facebook & Mobile
rnystrom
0
75
Open Source for the Open Mind
rnystrom
2
190
Mobile Debugging
rnystrom
0
100
Migrating to iOS 7
rnystrom
1
260
Minimal-first Design & Development
rnystrom
1
140
Learning iOS: Part 1
rnystrom
3
80
Other Decks in Programming
See All in Programming
PostgreSQLで手軽にDuckDBを使う!DuckDB&pg_duckdb入門/osc25hi-duckdb
takahashiikki
0
230
JETLS.jl ─ A New Language Server for Julia
abap34
2
470
0→1 フロントエンド開発 Tips🚀 #レバテックMeetup
bengo4com
0
450
チームをチームにするEM
hitode909
0
430
Pythonではじめるオープンデータ分析〜書籍の紹介と書籍で紹介しきれなかった事例の紹介〜
welliving
3
690
Developing static sites with Ruby
okuramasafumi
0
340
20251212 AI 時代的 Legacy Code 營救術 2025 WebConf
mouson
0
230
AIエンジニアリングのご紹介 / Introduction to AI Engineering
rkaga
8
3.5k
Basic Architectures
denyspoltorak
0
150
AtCoder Conference 2025「LLM時代のAHC」
imjk
2
620
Spinner 軸ズレ現象を調べたらレンダリング深淵に飲まれた #レバテックMeetup
bengo4com
1
210
DevFest Android in Korea 2025 - 개발자 커뮤니티를 통해 얻는 가치
wisemuji
0
180
Featured
See All Featured
Typedesign – Prime Four
hannesfritz
42
2.9k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
333
22k
Hiding What from Whom? A Critical Review of the History of Programming languages for Music
tomoyanonymous
1
330
Put a Button on it: Removing Barriers to Going Fast.
kastner
60
4.1k
Facilitating Awesome Meetings
lara
57
6.7k
DBのスキルで生き残る技術 - AI時代におけるテーブル設計の勘所
soudai
PRO
61
47k
Believing is Seeing
oripsolob
0
18
A Modern Web Designer's Workflow
chriscoyier
698
190k
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
34
2.6k
sira's awesome portfolio website redesign presentation
elsirapls
0
99
Designing for Performance
lara
610
70k
The AI Revolution Will Not Be Monopolized: How open-source beats economies of scale, even for LLMs
inesmontani
PRO
3
2.8k
Transcript
Drawing with Code @_ryannystrom
QuartzCore.framework
None
None
Runs on CPU Runs on GPU
Geometry
MYView
MYView
MYView
None
(0, 0)
(0, 0) (width, height)
struct CGPoint {! CGFloat x;! CGFloat y;! };! typedef struct
CGPoint CGPoint;
struct CGSize {! CGFloat width;! CGFloat height;! };! typedef struct
CGSize CGSize;
struct CGRect {! CGPoint origin;! CGSize size;! };! typedef struct
CGRect CGRect;
UIView *view = [[UIView alloc] init];! view.frame = CGRectMake(0, 0,
200, 150);
UIView *view = [[UIView alloc] init];! view.frame = {0, 0,
200, 150};
480 320 (0, 0) (200, 150)
480 320 (0, 0) (200, 150)
Drawing
@interface MYView : UIView! // public properties + methods! @end
@implementation MYView! ! - (void)drawRect:(CGRect)rect {! // draw here! }!
! @end
- (void)drawRect:(CGRect)rect {! // get our current drawing context! CGContextRef
ctx = UIGraphicsGetCurrentContext();! // set the fill color! [[UIColor redColor] setFill];! // fill a rect! CGContextFillRect(ctx, rect);! } Square
None
[[UIColor redColor] setStroke];! CGContextSetLineWidth(ctx, 4);! CGContextStrokeRect(ctx, rect); Border
None
// draw border! [[UIColor greenColor] setStroke];! CGContextSetLineWidth(ctx, 4);! CGContextStrokeRect(ctx, rect);!
! // draw circle! [[UIColor redColor] setFill];! CGRect smaller = CGRectInset(rect, 20, 20);! CGContextFillEllipseInRect(ctx, smaller); Circle
None
CGContextSetShadowWithColor(ctx, CGSizeMake(5, 10), 5, [UIColor blackColor].CGColor);! ! [[UIColor redColor] setFill];!
CGRect smaller = CGRectInset(rect, 20, 20);! CGContextFillEllipseInRect(ctx, smaller); Shadow
None
[[UIColor redColor] setFill];! ! CGMutablePathRef path = CGPathCreateMutable();! CGPathMoveToPoint(path, NULL,
0, 0);! CGPathAddLineToPoint(path, NULL, rect.size.width, 0);! CGPathAddLineToPoint(path, NULL, rect.size.width / 2, rect.size.height);! CGContextAddPath(ctx, path);! ! CGContextFillPath(ctx); Path
None
// triangle drawing! [[UIColor whiteColor] setStroke];! {! CGContextSaveGState(ctx);! [[UIColor greenColor]
setFill];! [[UIColor blackColor] setStroke];! CGContextSetLineWidth(ctx, 4);! CGRect inner = CGRectInset(rect, 50, 50);! CGContextFillEllipseInRect(ctx, inner);! CGContextStrokeEllipseInRect(ctx, inner);! CGContextRestoreGState(ctx);! }! CGRect inner = CGRectInset(rect, 20, 20);! CGContextStrokeRect(ctx, inner); Layers
None
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();! CGFloat stops[] = {0, 1};! NSArray
*colors = @[! (id)[UIColor whiteColor].CGColor,! (id)[UIColor blackColor].CGColor,! ];! CGGradientRef gradient = CGGradientCreateWithColors(colorSpace,! (__bridge CFArrayRef)(colors),! stops);! CGContextDrawLinearGradient(ctx, gradient, rect.origin, CGPointMake(0, rect.size.height), 0); Gradient
None
CGContextFillEllipseInRect(ctx, rect);! CGPathRef path = CGPathCreateWithEllipseInRect(rect, NULL);! CGContextAddPath(ctx, path);! CGContextClip(ctx);!
! // gradient drawing Clipping
None
Real world
Background Shadow Clipped Gradient Border
Background Shadow Clipped Gradient Border
Background Shadow Clipped Gradient Border
Background Shadow Clipped Gradient Border
Background Shadow Clipped Gradient Border
Background Shadow Clipped Gradient Border
[demo]
github.com/rnystrom/M3Demo
Thanks. @_ryannystrom