Created
August 7, 2015 11:16
-
-
Save mzsima/81a9346f05d4e57b8865 to your computer and use it in GitHub Desktop.
simple stretch
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 | |
// stretch | |
// | |
// Created by MizushimaYusuke on 8/7/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 createBar]; | |
} | |
- (void)setupScene { | |
SCNView *sv = [[SCNView alloc] initWithFrame:self.view.bounds]; | |
sv.backgroundColor = [UIColor colorWithHue:0.5 saturation:0.4 brightness:0.9 alpha:1]; | |
sv.scene = [SCNScene scene]; | |
sv.allowsCameraControl = YES; | |
[self.view addSubview:sv]; | |
self.sceneView = sv; | |
} | |
- (void)createBar { | |
float rate = 3; | |
for (int i=0; i<20; i++) { | |
float x = (arc4random() % 10) * rate; | |
float y = (arc4random() % 10) * rate; | |
float z = (arc4random() % 10) * rate; | |
SCNBox *bar = [SCNBox boxWithWidth:5 height:0.5 length:0.5 chamferRadius:0]; | |
bar.firstMaterial.diffuse.contents = [UIColor whiteColor]; | |
SCNNode *barNode = [SCNNode nodeWithGeometry:bar]; | |
barNode.position = SCNVector3Make(x, y, z); | |
[self.sceneView.scene.rootNode addChildNode:barNode]; | |
float delay = (arc4random() % 3) * 0.5; | |
SCNAction *(^expandX)(float) = ^(float w){ | |
return [SCNAction customActionWithDuration:1.0 actionBlock:^(SCNNode *node, CGFloat elapsedTime) { | |
node.scale = SCNVector3Make(w * elapsedTime + 1, 1, 1); | |
}]; | |
}; | |
NSArray *actions = @[expandX(0.8), [SCNAction scaleTo:1 duration:1.0]]; | |
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delay * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ | |
[barNode runAction:[SCNAction repeatActionForever:[SCNAction sequence:actions]]]; | |
}); | |
} | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
blog : http://lepetit-prince.net/ios/?p=4222