Created
April 22, 2017 14:05
-
-
Save mzsima/570194154a7d42546420ca38cf2109cb to your computer and use it in GitHub Desktop.
u curve
This file contains 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 | |
// UCurve | |
// | |
// Created by MizushimaYusuke on 2017/04/22. | |
// Copyright © 2017 MizushimaYusuke. All rights reserved. | |
// | |
#import "ViewController.h" | |
@import SpriteKit; | |
@interface ViewController () | |
@property (nonatomic, weak) SKScene *scene; | |
@end | |
@implementation ViewController | |
- (void)viewDidLoad { | |
[super viewDidLoad]; | |
[self setupScene]; | |
[self createPattern]; | |
} | |
- (void)setupScene { | |
SKView *sv = [[SKView alloc] initWithFrame:self.view.bounds]; | |
SKScene *s = [SKScene sceneWithSize:sv.frame.size]; | |
s.backgroundColor = [UIColor darkGrayColor]; | |
[sv presentScene:s]; | |
[self.view addSubview:sv]; | |
self.scene = s; | |
} | |
- (void)createPattern { | |
for (int i=0; i<12; i++) { | |
for (int j=0; j<8; j++) { | |
SKNode *u = [self createU]; | |
u.name = @"u"; | |
u.position = CGPointMake(i * 70, j * 70); | |
[self.scene addChild:u]; | |
} | |
} | |
} | |
- (SKNode *)createU { | |
UIBezierPath *path = [UIBezierPath bezierPath]; | |
[path moveToPoint:CGPointMake(2.5, 0)]; | |
[path addLineToPoint:CGPointMake(2.5, 35)]; | |
[path addArcWithCenter:CGPointMake(20, 35) radius:17.5 startAngle:M_PI endAngle:0 clockwise:NO]; | |
[path addLineToPoint:CGPointMake(37.5, 0)]; | |
path.lineWidth = 5; | |
UIGraphicsBeginImageContextWithOptions(CGSizeMake(40, 60), false, 0); | |
[[UIColor colorWithHue:0.2 saturation:0.7 brightness:1 alpha:1] set]; | |
[path stroke]; | |
UIImage *img = UIGraphicsGetImageFromCurrentImageContext(); | |
UIGraphicsEndImageContext(); | |
SKTexture *texture =[SKTexture textureWithImage:img]; | |
SKSpriteNode *u = [SKSpriteNode spriteNodeWithTexture:texture]; | |
return u; | |
} | |
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event { | |
[self.scene enumerateChildNodesWithName:@"u" usingBlock:^(SKNode * _Nonnull node, BOOL * _Nonnull stop) { | |
float w = arc4random_uniform(10); | |
[node runAction:[SKAction rotateByAngle:M_PI * 0.25 * w duration:1.0]]; | |
}]; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
http://lepetit-prince.net/ios/?p=6201