Tiling and Zooming
ASCII Art
iOS SOHO!
June 9th, 2014
Daniel Doubrovkine
@dblockdotorg
Francisco De Goya Y Lucientes, Señora Sabasa Garcia, ca. 1806/1811
https://artsy.net/artwork/francisco-jose-de-goya-y-luci...
UIScrollView + UIImageView
UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:self.view.bounds];
[self.view ad...
CenterOnPoint
- (void)centerOnPoint:(CGPoint)point
{
CGFloat x = point.x - (self.view.frame.size.width / 2.0f);
CGFloat y ...
Zoom on Tap
!
{
UITapGestureRecognizer *doubleTap = [[UITapGestureRecognizer alloc] initWithTarget:self
action:@selector(h...
Pinch Zoom
{
scrollView.delegate = self;
scrollView.minimumZoomScale = 0.5;
scrollView.maximumZoomScale = 2;
}
!
- (void)s...
Different Images at Different Zoom Levels?
ARTiledImageDataSource
- (UIImage *)imageTileForLevel:(NSInteger)level x:(NSInteger)x y:(NSInteger)y;
- (CGSize)tileSize;
...
- (void)drawRect:(CGRect)rect
• Translate the CGRect into the tile coordinate system at this scale.
!
NSInteger firstCol =...
ARTiledImageView
ARTiledImageScrollView
https://github.com/dblock/ARTiledImageView
+ All The Size Maths
+ Scroll & Zoom Ge...
WHERE’S THE
ASCII ART?
seriously …
UIImage to Text to UIImage
static const NSString * UIImageViewASCII_CharacterMap = @" .,;_-`*”;
!
…
!
int r = rawData[byte...
//
// UIImage+ASCII.h
// Pods
//
// Created by Daniel Doubrovkine on 3/23/14.
//
//
!
#import <UIKit/UIKit.h>
!
@interface...
Zoom Tiled ASCII Art?
Daniel Doubrovkine
@dblockdotorg!
dblock@dblock.org!
!
http://iphone.artsy.net
https://github.com/dblock/ARImageViewInsideScrollView!
https://github.com/dblock/ARTiledImageView!
https://github.com/dblo...
Tiling and Zooming ASCII Art @ iOSoho
Upcoming SlideShare
Loading in …5
×

Tiling and Zooming ASCII Art @ iOSoho

679 views
484 views

Published on

New York, June 2014

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
679
On SlideShare
0
From Embeds
0
Number of Embeds
14
Actions
Shares
0
Downloads
3
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Tiling and Zooming ASCII Art @ iOSoho

  1. 1. Tiling and Zooming ASCII Art iOS SOHO! June 9th, 2014 Daniel Doubrovkine @dblockdotorg
  2. 2. Francisco De Goya Y Lucientes, Señora Sabasa Garcia, ca. 1806/1811 https://artsy.net/artwork/francisco-jose-de-goya-y-lucientes-senora-sabasa-garcia courtesy of the National Gallery of Art, Washington D.C.
  3. 3. 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;
  4. 4. 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)]; }
  5. 5. 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; }]; }
  6. 6. 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; }
  7. 7. Different Images at Different Zoom Levels?
  8. 8. ARTiledImageDataSource - (UIImage *)imageTileForLevel:(NSInteger)level x:(NSInteger)x y:(NSInteger)y; - (CGSize)tileSize; - (CGSize)imageSize; - (NSInteger)minimumImageZoomLevel; - (NSInteger)maximumImageZoomLevel;
  9. 9. - (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.
  10. 10. ARTiledImageView ARTiledImageScrollView https://github.com/dblock/ARTiledImageView + All The Size Maths + Scroll & Zoom Gestures + In-Memory Tile Cache + Local vs. Remote Tiles
  11. 11. WHERE’S THE ASCII ART? seriously …
  12. 12. 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];
  13. 13. // // 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
  14. 14. Zoom Tiled ASCII Art? Daniel Doubrovkine @dblockdotorg! dblock@dblock.org! ! http://iphone.artsy.net
  15. 15. https://github.com/dblock/ARImageViewInsideScrollView! https://github.com/dblock/ARTiledImageView! https://github.com/dblock/ARASCIISwizzle! https://github.com/objectiveSee/DRKonamiCode

×