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
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
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
77
Open Source for the Open Mind
rnystrom
2
190
Mobile Debugging
rnystrom
0
110
Migrating to iOS 7
rnystrom
1
260
Minimal-first Design & Development
rnystrom
1
140
Learning iOS: Part 1
rnystrom
3
81
Other Decks in Programming
See All in Programming
Basic Architectures
denyspoltorak
0
660
Patterns of Patterns
denyspoltorak
0
1.4k
AI時代のキャリアプラン「技術の引力」からの脱出と「問い」へのいざない / tech-gravity
minodriven
20
7k
フロントエンド開発の勘所 -複数事業を経験して見えた判断軸の違い-
heimusu
7
2.8k
360° Signals in Angular: Signal Forms with SignalStore & Resources @ngLondon 01/2026
manfredsteyer
PRO
0
120
Package Management Learnings from Homebrew
mikemcquaid
0
210
LLM Observabilityによる 対話型音声AIアプリケーションの安定運用
gekko0114
2
420
カスタマーサクセス業務を変革したヘルススコアの実現と学び
_hummer0724
0
670
生成AIを使ったコードレビューで定性的に品質カバー
chiilog
1
260
ぼくの開発環境2026
yuzneri
0
170
CSC307 Lecture 05
javiergs
PRO
0
500
Fragmented Architectures
denyspoltorak
0
150
Featured
See All Featured
Building Better People: How to give real-time feedback that sticks.
wjessup
370
20k
コードの90%をAIが書く世界で何が待っているのか / What awaits us in a world where 90% of the code is written by AI
rkaga
60
42k
Embracing the Ebb and Flow
colly
88
5k
How to audit for AI Accessibility on your Front & Back End
davetheseo
0
180
So, you think you're a good person
axbom
PRO
2
1.9k
DevOps and Value Stream Thinking: Enabling flow, efficiency and business value
helenjbeal
1
90
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
128
55k
Un-Boring Meetings
codingconduct
0
200
Optimising Largest Contentful Paint
csswizardry
37
3.6k
Impact Scores and Hybrid Strategies: The future of link building
tamaranovitovic
0
200
Chasing Engaging Ingredients in Design
codingconduct
0
110
Making the Leap to Tech Lead
cromwellryan
135
9.7k
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