More Related Content Similar to Tiling and Zooming ASCII Art @ iOSoho (20) More from Daniel Doubrovkine (20) Tiling and Zooming ASCII Art @ iOSoho2. 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.
4. 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;
5. 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)];
}
6. 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;
}];
}
7. 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;
}
10. - (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.
13. 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];
14. //
// 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
15. Zoom Tiled ASCII Art?
Daniel Doubrovkine
@dblockdotorg!
dblock@dblock.org!
!
http://iphone.artsy.net