tiling and zooming ascii art @ iosoho
DESCRIPTION
New York, June 2014TRANSCRIPT
Tiling and Zooming ASCII Art
iOS SOHO!June 9th, 2014
Daniel Doubrovkine @dblockdotorg
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.
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;
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)]; }
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; }]; }
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; }
Different Images at Different Zoom Levels?
ARTiledImageDataSource
- (UIImage *)imageTileForLevel:(NSInteger)level x:(NSInteger)x y:(NSInteger)y; - (CGSize)tileSize; - (CGSize)imageSize; - (NSInteger)minimumImageZoomLevel; - (NSInteger)maximumImageZoomLevel;
- (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.
ARTiledImageView ARTiledImageScrollView https://github.com/dblock/ARTiledImageView
+ All The Size Maths + Scroll & Zoom Gestures + In-Memory Tile Cache + Local vs. Remote Tiles
WHERE’S THE ASCII ART?
seriously …
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];
// // 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
Zoom Tiled ASCII Art?
Daniel Doubrovkine @dblockdotorg!
http://iphone.artsy.net
https://github.com/dblock/ARImageViewInsideScrollView!https://github.com/dblock/ARTiledImageView!
https://github.com/dblock/ARASCIISwizzle!https://github.com/objectiveSee/DRKonamiCode