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
200
Facebook Pop
rnystrom
2
640
Facebook & Mobile
rnystrom
0
73
Open Source for the Open Mind
rnystrom
2
190
Mobile Debugging
rnystrom
0
97
Migrating to iOS 7
rnystrom
1
220
Minimal-first Design & Development
rnystrom
1
140
Learning iOS: Part 1
rnystrom
3
80
Other Decks in Programming
See All in Programming
SODA - FACT BOOK
sodainc
1
1.1k
iOSアプリ開発で 関数型プログラミングを実現する The Composable Architectureの紹介
yimajo
2
210
Perplexity Slack Botを作ってAI活用を進めた話 / AI Engineering Summit プレイベント
n3xem
0
670
統一感のある Go コードを生成 AI の力で手にいれる
otakakot
1
3k
都市をデータで見るってこういうこと PLATEAU属性情報入門
nokonoko1203
1
550
ドメインモデリングにおける抽象の役割、tagless-finalによるDSL構築、そして型安全な最適化
knih
11
2k
Bytecode Manipulation 으로 생산성 높이기
bigstark
2
360
来たるべき 8.0 に備えて React 19 新機能と React Router 固有機能の取捨選択とすり合わせを考える
oukayuka
2
830
つよそうにふるまい、つよい成果を出すのなら、つよいのかもしれない
irof
1
300
A2A プロトコルを試してみる
azukiazusa1
2
960
ReadMoreTextView
fornewid
1
450
アンドパッドの Go 勉強会「 gopher 会」とその内容の紹介
andpad
0
250
Featured
See All Featured
Building Adaptive Systems
keathley
43
2.6k
Typedesign – Prime Four
hannesfritz
42
2.7k
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
48
2.8k
Rebuilding a faster, lazier Slack
samanthasiow
81
9k
Building Flexible Design Systems
yeseniaperezcruz
328
39k
Embracing the Ebb and Flow
colly
86
4.7k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
35
2.3k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
31
1.2k
How to Ace a Technical Interview
jacobian
277
23k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
667
120k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
228
22k
Improving Core Web Vitals using Speculation Rules API
sergeychernyshev
16
940
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