Created
September 11, 2015 11:57
-
-
Save mzsima/ead1f37d534a8ef5b7a1 to your computer and use it in GitHub Desktop.
shredded paging
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// ViewController.m | |
// ShreddedPaging | |
// | |
// Created by MizushimaYusuke on 9/11/15. | |
// Copyright (c) 2015 MizushimaYusuke. All rights reserved. | |
// | |
#import "ViewController.h" | |
@import SceneKit; | |
@interface ViewController () | |
@property (nonatomic, weak) SCNView *sceneView; | |
@end | |
@implementation ViewController | |
- (void)viewDidLoad { | |
[super viewDidLoad]; | |
[self setupScene]; | |
[self createPaper:[UIColor whiteColor]]; | |
[self createCamera]; | |
} | |
- (void)setupScene { | |
SCNView *sceneView = [[SCNView alloc] initWithFrame:self.view.bounds]; | |
sceneView.scene = [SCNScene scene]; | |
sceneView.backgroundColor = [UIColor lightGrayColor]; | |
sceneView.autoenablesDefaultLighting = YES; | |
[self.view addSubview:sceneView]; | |
self.sceneView = sceneView; | |
} | |
- (void)createPaper:(UIColor *)color { | |
SCNNode *page = [SCNNode node]; | |
page.name = @"page"; | |
[self.sceneView.scene.rootNode addChildNode:page]; | |
SCNBox *strip = [SCNBox boxWithWidth:5 height:0.2 length:0.01 chamferRadius:0]; | |
strip.firstMaterial.diffuse.contents = color; | |
for (int i=0; i<50; i++) { | |
SCNNode *stripePaper = [SCNNode nodeWithGeometry:strip]; | |
stripePaper.pivot = SCNMatrix4MakeTranslation(2.5, 0, 0); | |
stripePaper.position = SCNVector3Make(0, i * 0.2, 0); | |
[page addChildNode:stripePaper]; | |
} | |
} | |
- (void)createCamera { | |
SCNNode *camera = [SCNNode node]; | |
camera.camera = [SCNCamera camera]; | |
camera.position = SCNVector3Make(0, 0, 20); | |
[self.sceneView.scene.rootNode addChildNode:camera]; | |
} | |
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { | |
static int count = 1; | |
SCNNode *page = [self.sceneView.scene.rootNode childNodeWithName:@"page" recursively:NO]; | |
page.position = SCNVector3Make(0, 0, 0.001 * (10 - ++count)); | |
[page.childNodes enumerateObjectsUsingBlock:^(SCNNode *n, NSUInteger i, BOOL *stop) { | |
[n runAction: | |
[SCNAction sequence:@[[SCNAction waitForDuration:i * 0.05], [SCNAction moveTo:SCNVector3Make(n.position.x, n.position.y, 0.002 * count) duration:0],[SCNAction rotateByX:0 y:M_PI z:0 duration:1.0]]] | |
]; | |
}]; | |
page.name = @""; | |
float hue = count * 0.1; | |
[self createPaper:[UIColor colorWithHue:hue saturation:0.4 brightness:1 alpha:1]]; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment