@@ -14,13 +14,31 @@ @implementation USKFractalView {
14
14
CGRect currentCRect;
15
15
}
16
16
17
+ @synthesize delegate;
18
+ @synthesize currentMagnification;
19
+
17
20
- (id )initWithFrame : (CGRect )frame
18
21
{
19
22
self = [super initWithFrame: frame];
20
23
if (self) {
21
24
// Initialization code
22
25
self.contentMode = UIViewContentModeScaleAspectFit;
23
26
self.userInteractionEnabled = YES ;
27
+
28
+ width = frame.size .width ;
29
+ height = frame.size .height ;
30
+
31
+ // if ([[UIScreen mainScreen] respondsToSelector:@selector(displayLinkWithTarget:selector:)] &&
32
+ // ([UIScreen mainScreen].scale == 2.0)) {
33
+ // // Retina display
34
+ // width = frame.size.width * 2.0;
35
+ // height = frame.size.height * 2.0;
36
+ // } else {
37
+ // // non-Retina display
38
+ // width = frame.size.width;
39
+ // height = frame.size.height;
40
+ // }
41
+
24
42
[self drawMandelbrotSet ];
25
43
}
26
44
return self;
@@ -29,6 +47,8 @@ - (id)initWithFrame:(CGRect)frame
29
47
- (void )drawMandelbrotSet
30
48
{
31
49
CGRect complexRect = CGRectMake (-2.0 , -2.0 , 4.0 , 4.0 );
50
+ currentMagnification = 1.0 ;
51
+ [delegate updateMagnificationLabel ];
32
52
[self drawMandelbrotSetInComplexRect: complexRect];
33
53
}
34
54
@@ -41,9 +61,6 @@ - (void)drawMandelbrotSetInComplexRect:(CGRect)cRect
41
61
NSUInteger iteration;
42
62
double _Complex z0 = 0 + 0 * I;
43
63
44
- width = 1536 ;
45
- height = width;
46
-
47
64
size_t bytePerPixel = sizeof (unsigned char ) * 3 ;
48
65
size_t bitsPerPixel, bytesPerRow;
49
66
unsigned char *imageData = calloc (width * height, sizeof (unsigned char ) * bytePerPixel);
@@ -113,10 +130,15 @@ - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
113
130
CGPoint complexP = CGPointMake (currentCRect.origin .x + currentCRect.size .width * relativeP.x ,
114
131
currentCRect.origin .y + currentCRect.size .height * relativeP.y );
115
132
CGSize newSize = CGSizeMake (currentCRect.size .width / magnification, currentCRect.size .height / magnification);
116
- [self drawMandelbrotSetInComplexRect: CGRectMake (complexP.x - newSize.width / 2.0 ,
117
- complexP.y - newSize.height / 2.0 ,
118
- newSize.width,
119
- newSize.height)];
133
+
134
+ [UIView animateWithDuration: 0.5 animations: ^{
135
+ [self drawMandelbrotSetInComplexRect: CGRectMake (complexP.x - newSize.width / 2.0 ,
136
+ complexP.y - newSize.height / 2.0 ,
137
+ newSize.width,
138
+ newSize.height)];
139
+ }];
140
+ currentMagnification *= magnification;
141
+ [delegate updateMagnificationLabel ];
120
142
}
121
143
122
144
0 commit comments