tiling and zooming ascii art @ iosoho

16
Tiling and Zooming ASCII Art iOS SOHO June 9th, 2014 Daniel Doubrovkine @dblockdotorg

Upload: daniel-doubrovkine

Post on 24-Jan-2015

222 views

Category:

Technology


0 download

DESCRIPTION

New York, June 2014

TRANSCRIPT

Page 1: Tiling and Zooming ASCII Art @ iOSoho

Tiling and Zooming ASCII Art

iOS SOHO!June 9th, 2014

Daniel Doubrovkine @dblockdotorg

Page 2: Tiling and Zooming ASCII Art @ iOSoho

Francisco De Goya Y Lucientes, Señora Sabasa Garcia, ca. 1806/1811https://artsy.net/artwork/francisco-jose-de-goya-y-lucientes-senora-sabasa-garcia

courtesy of the National Gallery of Art, Washington D.C.

Page 3: Tiling and Zooming ASCII Art @ iOSoho
Page 4: Tiling and Zooming ASCII Art @ iOSoho

UIScrollView + UIImageView UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:self.view.bounds]; [self.view addSubview:scrollView]; ! UIImage *image = [UIImage imageNamed:@"boy.jpg"]; UIImageView *imageView = [[UIImageView alloc] initWithImage:image]; [scrollView addSubview:imageView]; ! scrollView.contentSize = image.size;

Page 5: Tiling and Zooming ASCII Art @ iOSoho

CenterOnPoint- (void)centerOnPoint:(CGPoint)point { CGFloat x = point.x - (self.view.frame.size.width / 2.0f); CGFloat y = point.y - (self.view.frame.size.height / 2.0f); [self.scrollView setContentOffset:CGPointMake(round(x), round(y)); } !!{ [self centerOnPoint:CGPointMake(image.size.width / 2, image.size.height / 2)]; }

Page 6: Tiling and Zooming ASCII Art @ iOSoho

Zoom on Tap!

{ UITapGestureRecognizer *doubleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleDoubleTap:)]; [doubleTap setNumberOfTapsRequired:2]; [self.view addGestureRecognizer:doubleTap]; } !- (void)handleDoubleTap:(UIGestureRecognizer *)gestureRecognizer { [UIView animateWithDuration:0.3 animations:^{ self.imageView.frame = CGRectMake(0, 0, self.imageView.frame.size.width + 100, self.imageView.frame.size.height + 100); self.scrollView.contentSize = self.imageView.frame.size; }]; }

Page 7: Tiling and Zooming ASCII Art @ iOSoho

Pinch Zoom{ scrollView.delegate = self; scrollView.minimumZoomScale = 0.5; scrollView.maximumZoomScale = 2; } !- (void)scrollViewDidZoom:(UIScrollView *)scrollView { self.imageView.frame = CGRectMake(0, 0, self.image.size.width * self.scrollView.zoomScale, self.image.size.height * self.scrollView.zoomScale); self.scrollView.contentSize = self.imageView.frame.size; } !- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView { return self.imageView; }

Page 8: Tiling and Zooming ASCII Art @ iOSoho

Different Images at Different Zoom Levels?

Page 9: Tiling and Zooming ASCII Art @ iOSoho

ARTiledImageDataSource

- (UIImage *)imageTileForLevel:(NSInteger)level x:(NSInteger)x y:(NSInteger)y; - (CGSize)tileSize; - (CGSize)imageSize; - (NSInteger)minimumImageZoomLevel; - (NSInteger)maximumImageZoomLevel;

Page 10: Tiling and Zooming ASCII Art @ iOSoho

- (void)drawRect:(CGRect)rect

• Translate the CGRect into the tile coordinate system at this scale. ! NSInteger firstCol = floor(CGRectGetMinX(rect) / tileSize.width); … ! for (NSInteger row = firstRow; row <= lastRow; row++) { for (NSInteger col = firstCol; col <= lastCol; col++) { !

• Fetch each tile & draw with drawInRect:blendMode.

Page 11: Tiling and Zooming ASCII Art @ iOSoho

ARTiledImageView ARTiledImageScrollView https://github.com/dblock/ARTiledImageView

+ All The Size Maths + Scroll & Zoom Gestures + In-Memory Tile Cache + Local vs. Remote Tiles

Page 12: Tiling and Zooming ASCII Art @ iOSoho

WHERE’S THE ASCII ART?

seriously …

Page 13: Tiling and Zooming ASCII Art @ iOSoho

UIImage to Text to UIImage

static const NSString * UIImageViewASCII_CharacterMap = @" .,;_-`*”; !… !int r = rawData[byteIndex] & 0xff; int g = (rawData[byteIndex] >> 8) & 0xff; int b = (rawData[byteIndex] >> 16) & 0xff; !NSInteger characterIndex = 7 - (((int)(r + g + b)/3) >> 5) & 0x7; ![UIImageViewASCII_CharacterMap characterAtIndex:characterIndex];

Page 14: Tiling and Zooming ASCII Art @ iOSoho

// // UIImage+ASCII.h // Pods // // Created by Daniel Doubrovkine on 3/23/14. // // !#import <UIKit/UIKit.h> !@interface UIImage (ASCII) !/** * Convert an image to ASCII. * * @param font ASCII font. * @param color Text color. * * @return Returns an image with the ASCII text. */ - (UIImage *)asciiImage:(UIFont *)font color:(UIColor *)color; !/** * Convert an image to ASCII. * * @return Returns the ASCII text. */ - (NSString *)asciiText; !@end

Page 15: Tiling and Zooming ASCII Art @ iOSoho

Zoom Tiled ASCII Art?

Daniel Doubrovkine @dblockdotorg!

[email protected]!!

http://iphone.artsy.net

Page 16: Tiling and Zooming ASCII Art @ iOSoho

https://github.com/dblock/ARImageViewInsideScrollView!https://github.com/dblock/ARTiledImageView!

https://github.com/dblock/ARASCIISwizzle!https://github.com/objectiveSee/DRKonamiCode