Skip to content

Instantly share code, notes, and snippets.

@mzsima
Created July 15, 2016 13:02
Show Gist options
  • Save mzsima/ce9960d7aa9549b367169e3df7578115 to your computer and use it in GitHub Desktop.
Save mzsima/ce9960d7aa9549b367169e3df7578115 to your computer and use it in GitHub Desktop.
wagara asa
//
// ViewController.m
// WagaraAsa
//
// Created by MizushimaYusuke on 7/15/16.
// Copyright © 2016 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 colorWithHue:0 saturation:0.6 brightness:0.7 alpha:1];
[sv presentScene:s];
[self.view addSubview:sv];
self.scene = s;
}
- (void)createPattern {
for (int i=0; i<100; i++) {
float x = (i % 10) * 40 * cos(M_PI / 6.0) + 30;
float y = (i / 10) * 20 + 160;
for (int j = 0; j<6; j++) {
SKNode *node = [self createPart];
node.position = CGPointMake(x, y);
node.name = [NSString stringWithFormat:@"part %d", j];
}
}
}
- (SKNode *)createPart {
float l = 20;
CGPoint o = CGPointMake(l * cos(M_PI / 3.0) * 0.5, l * 0.5);
CGPoint p1 = CGPointZero;
CGPoint p2 = CGPointMake(0, l);
CGPoint p3 = CGPointMake(l * cos(M_PI / 6.0), l * sin(M_PI / 6.0));
UIBezierPath *path = [UIBezierPath bezierPath];
[path moveToPoint:p1];
[path addLineToPoint:p2];
[path addLineToPoint:p3];
[path closePath];
[path moveToPoint:o];
[path addLineToPoint:p1];
[path moveToPoint:o];
[path addLineToPoint:p2];
[path moveToPoint:o];
[path addLineToPoint:p3];
path.lineWidth = 2;
SKShapeNode *part = [SKShapeNode shapeNodeWithPath:path.CGPath];
part.fillColor = [UIColor clearColor];
part.strokeColor = [UIColor whiteColor];
[self.scene addChild:part];
part.position = CGPointMake(100, 100);
return part;
}
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
[self.scene.children enumerateObjectsUsingBlock:^(SKNode * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
if ([obj.name hasPrefix:@"part"]) {
int no = [[obj.name componentsSeparatedByString:@" "][1] intValue];
[obj runAction:[SKAction rotateByAngle:no * M_PI / 3.0 duration:3.0]];
}
}];
}
@end
@mzsima
Copy link
Author

mzsima commented Jul 15, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment