Skip to content

Commit 9879444

Browse files
committed
first commit
1 parent 462ec22 commit 9879444

File tree

5 files changed

+153
-4
lines changed

5 files changed

+153
-4
lines changed

Diff for: iMandelbrot.xcodeproj/project.pbxproj

+9
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
43CDE23B1819EDD300208C17 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 43CDE21A1819EDD300208C17 /* UIKit.framework */; };
2323
43CDE2431819EDD400208C17 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 43CDE2411819EDD400208C17 /* InfoPlist.strings */; };
2424
43CDE2451819EDD400208C17 /* iMandelbrotTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 43CDE2441819EDD400208C17 /* iMandelbrotTests.m */; };
25+
43CDE2501819EE6900208C17 /* USKFractalView.m in Sources */ = {isa = PBXBuildFile; fileRef = 43CDE24F1819EE6900208C17 /* USKFractalView.m */; };
2526
/* End PBXBuildFile section */
2627

2728
/* Begin PBXContainerItemProxy section */
@@ -55,6 +56,8 @@
5556
43CDE2401819EDD300208C17 /* iMandelbrotTests-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "iMandelbrotTests-Info.plist"; sourceTree = "<group>"; };
5657
43CDE2421819EDD400208C17 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = "<group>"; };
5758
43CDE2441819EDD400208C17 /* iMandelbrotTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = iMandelbrotTests.m; sourceTree = "<group>"; };
59+
43CDE24E1819EE6900208C17 /* USKFractalView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = USKFractalView.h; sourceTree = "<group>"; };
60+
43CDE24F1819EE6900208C17 /* USKFractalView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = USKFractalView.m; sourceTree = "<group>"; };
5861
/* End PBXFileReference section */
5962

6063
/* Begin PBXFrameworksBuildPhase section */
@@ -120,6 +123,8 @@
120123
43CDE22B1819EDD300208C17 /* Main_iPad.storyboard */,
121124
43CDE22E1819EDD300208C17 /* USKViewController.h */,
122125
43CDE22F1819EDD300208C17 /* USKViewController.m */,
126+
43CDE24E1819EE6900208C17 /* USKFractalView.h */,
127+
43CDE24F1819EE6900208C17 /* USKFractalView.m */,
123128
43CDE2311819EDD300208C17 /* Images.xcassets */,
124129
43CDE21D1819EDD300208C17 /* Supporting Files */,
125130
);
@@ -256,6 +261,7 @@
256261
files = (
257262
43CDE2301819EDD300208C17 /* USKViewController.m in Sources */,
258263
43CDE2271819EDD300208C17 /* USKAppDelegate.m in Sources */,
264+
43CDE2501819EE6900208C17 /* USKFractalView.m in Sources */,
259265
43CDE2231819EDD300208C17 /* main.m in Sources */,
260266
);
261267
runOnlyForDeploymentPostprocessing = 0;
@@ -393,6 +399,7 @@
393399
buildSettings = {
394400
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
395401
ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage;
402+
GCC_OPTIMIZATION_LEVEL = 0;
396403
GCC_PRECOMPILE_PREFIX_HEADER = YES;
397404
GCC_PREFIX_HEADER = "iMandelbrot/iMandelbrot-Prefix.pch";
398405
INFOPLIST_FILE = "iMandelbrot/iMandelbrot-Info.plist";
@@ -475,6 +482,7 @@
475482
43CDE24A1819EDD400208C17 /* Release */,
476483
);
477484
defaultConfigurationIsVisible = 0;
485+
defaultConfigurationName = Release;
478486
};
479487
43CDE24B1819EDD400208C17 /* Build configuration list for PBXNativeTarget "iMandelbrotTests" */ = {
480488
isa = XCConfigurationList;
@@ -483,6 +491,7 @@
483491
43CDE24D1819EDD400208C17 /* Release */,
484492
);
485493
defaultConfigurationIsVisible = 0;
494+
defaultConfigurationName = Release;
486495
};
487496
/* End XCConfigurationList section */
488497
};

Diff for: iMandelbrot/Base.lproj/Main_iPad.storyboard

+8-4
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
11
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2-
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="4451" systemVersion="13A461" targetRuntime="iOS.CocoaTouch.iPad" propertyAccessControl="none" useAutolayout="YES" initialViewController="BYZ-38-t0r">
2+
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="4510" systemVersion="12F45" targetRuntime="iOS.CocoaTouch.iPad" propertyAccessControl="none" useAutolayout="YES" initialViewController="BYZ-38-t0r">
33
<dependencies>
4-
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="3676"/>
4+
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="3742"/>
55
</dependencies>
66
<scenes>
7-
<!--class Prefix:identifier View Controller-->
7+
<!--View Controller-->
88
<scene sceneID="tne-QT-ifu">
99
<objects>
1010
<viewController id="BYZ-38-t0r" customClass="USKViewController" sceneMemberID="viewController">
11+
<layoutGuides>
12+
<viewControllerLayoutGuide type="top" id="tb2-Sg-6NF"/>
13+
<viewControllerLayoutGuide type="bottom" id="sru-qw-uLJ"/>
14+
</layoutGuides>
1115
<view key="view" contentMode="scaleToFill" id="8bC-Xf-vdC">
12-
<rect key="frame" x="0.0" y="20" width="768" height="1004"/>
16+
<rect key="frame" x="0.0" y="0.0" width="768" height="1024"/>
1317
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
1418
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
1519
</view>

Diff for: iMandelbrot/USKFractalView.h

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//
2+
// USKFractalView.h
3+
// iMandelbrot
4+
//
5+
// Created by Yusuke Iwama on 10/25/13.
6+
// Copyright (c) 2013 Yusuke Iwama. All rights reserved.
7+
//
8+
9+
#import <UIKit/UIKit.h>
10+
11+
@interface USKFractalView : UIImageView
12+
13+
- (void)drawMandelbrotSetInComplexRect:(CGRect)cRect;
14+
15+
@end

Diff for: iMandelbrot/USKFractalView.m

+115
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
//
2+
// USKFractalView.m
3+
// iMandelbrot
4+
//
5+
// Created by Yusuke Iwama on 10/25/13.
6+
// Copyright (c) 2013 Yusuke Iwama. All rights reserved.
7+
//
8+
9+
#import "USKFractalView.h"
10+
#import "complex.h"
11+
12+
@implementation USKFractalView {
13+
size_t width, height;
14+
}
15+
16+
- (id)initWithFrame:(CGRect)frame
17+
{
18+
self = [super initWithFrame:frame];
19+
if (self) {
20+
// Initialization code
21+
self.contentMode = UIViewContentModeScaleAspectFit;
22+
self.userInteractionEnabled = YES;
23+
[self drawMandelbrotSetInComplexRect:CGRectMake(-2.0, -2.0, 4.0, 4.0)];
24+
}
25+
return self;
26+
}
27+
28+
- (void)drawMandelbrotSetInComplexRect:(CGRect)cRect
29+
{
30+
// Draw Mandelbrot Set
31+
NSUInteger maxIteration = 100;
32+
NSUInteger iteration;
33+
double _Complex z0 = 0 + 0 * I;
34+
35+
width = 1536;
36+
height = width;
37+
38+
size_t bytePerPixel = sizeof(unsigned char) * 3;
39+
size_t bitsPerPixel, bytesPerRow;
40+
unsigned char *imageData = calloc(width * height, sizeof(unsigned char) * bytePerPixel);
41+
42+
for (NSUInteger i = 0; i < height; i++) {
43+
for (NSUInteger j = 0; j < width; j++) {
44+
double _Complex c = cRect.size.width * j / width + cRect.origin.x + (cRect.size.height * i / height + cRect.origin.y) * I;
45+
double _Complex z = z0;
46+
for (iteration = 0; iteration < maxIteration; iteration++) {
47+
z = z * z + c;
48+
if (cabs(z) > 2) {
49+
break;
50+
}
51+
}
52+
if (cabs(z) > 1) {
53+
imageData[(i * height + j) * bytePerPixel + 0] = 255 * (1 - iteration / (double)maxIteration);
54+
imageData[(i * height + j) * bytePerPixel + 1] = 255 * (1 - iteration / (double)maxIteration);
55+
imageData[(i * height + j) * bytePerPixel + 2] = 255 * (1 - iteration / (double)maxIteration);
56+
}
57+
}
58+
}
59+
60+
61+
CGBitmapInfo bitmapInfo = 0;
62+
63+
// データをNSData型にラップ
64+
NSData *data = [NSData dataWithBytes:imageData
65+
length:bytePerPixel * width * height];
66+
67+
// NSDataを元にDataProviderを作成し、それを元にCGImageRefを作成
68+
bitsPerPixel = 8 * bytePerPixel;
69+
bytesPerRow = bytePerPixel * width;
70+
bitmapInfo = kCGImageAlphaNone | kCGBitmapByteOrderDefault;
71+
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
72+
CGDataProviderRef provider = CGDataProviderCreateWithCFData((__bridge CFDataRef)data);
73+
CGImageRef imageRef = CGImageCreate(width, // Width
74+
height, // Height
75+
sizeof(unsigned char) * 8, // Bits per component
76+
bitsPerPixel, // Bits per pixel
77+
bytesPerRow, // Bytes per row
78+
colorSpace, // Colorspace
79+
bitmapInfo, // Bitmap info flags
80+
provider, // CGDataProviderRef
81+
NULL, // Decode
82+
false, // Should interpolate
83+
kCGRenderingIntentDefault); // Intent
84+
85+
// CGImageRefを使ってUIImageとして初期化
86+
// imageRefだけでは倍率と方向が不明なため別途指定する
87+
UIImage *mandelbrotSetImage = [[UIImage alloc] initWithCGImage:imageRef
88+
scale:0
89+
orientation:UIImageOrientationUp];
90+
91+
// 不要になった情報を削除
92+
CGImageRelease(imageRef);
93+
CGDataProviderRelease(provider);
94+
CGColorSpaceRelease(colorSpace);
95+
96+
self.image = mandelbrotSetImage;
97+
}
98+
99+
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
100+
{
101+
CGPoint p = [[touches anyObject] locationInView:self];
102+
printf("p = (%f, %f)\tc = (%f, %f)\n", p.x, p.y, p.x / width - 0.5, p.y / height - 0.5);
103+
[self drawMandelbrotSetInComplexRect:CGRectMake(p.x / width - 0.5, p.y / height - 0.5, 1.0, 1.0)];
104+
}
105+
106+
/*
107+
// Only override drawRect: if you perform custom drawing.
108+
// An empty implementation adversely affects performance during animation.
109+
- (void)drawRect:(CGRect)rect
110+
{
111+
// Drawing code
112+
}
113+
*/
114+
115+
@end

Diff for: iMandelbrot/USKViewController.m

+6
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
//
88

99
#import "USKViewController.h"
10+
#import "USKFractalView.h"
1011

1112
@interface USKViewController ()
1213

@@ -18,6 +19,11 @@ - (void)viewDidLoad
1819
{
1920
[super viewDidLoad];
2021
// Do any additional setup after loading the view, typically from a nib.
22+
23+
USKFractalView *iv = [[USKFractalView alloc] initWithFrame:CGRectMake(0, 0, [[UIScreen mainScreen] bounds].size.width, [[UIScreen mainScreen] bounds].size.width)];
24+
iv.center = self.view.center;
25+
[self.view addSubview:iv];
26+
self.view.backgroundColor = [UIColor whiteColor];
2127
}
2228

2329
- (void)didReceiveMemoryWarning

0 commit comments

Comments
 (0)