Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // ViewController.m
- // ArgylePattern
- //
- // Created by Yusuke Mizushima on 2016/12/04.
- // Copyright © 2016 Yusuke Mizushima. All rights reserved.
- //
- #import "ViewController.h"
- @import SpriteKit;
- @interface ViewController ()
- @property (nonatomic, weak) SKScene *scene;
- @end
- #define UIColorHex(rgbValue) [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 green:((float)((rgbValue & 0xFF00) >> 8))/255.0 blue:((float)(rgbValue & 0xFF))/255.0 alpha:1.0]
- @implementation ViewController
- - (void)viewDidLoad {
- [super viewDidLoad];
- [self setupScene];
- [self createArgylePattern];
- }
- - (void)setupScene {
- SKView *sv = [[SKView alloc] initWithFrame:self.view.bounds];
- SKScene *s = [SKScene sceneWithSize:sv.frame.size];
- [sv presentScene:s];
- [self.view addSubview:sv];
- self.scene = s;
- }
- - (void)createArgylePattern {
- float l = 50;
- UIBezierPath *path = [UIBezierPath bezierPathWithRect:CGRectMake(-l/2.0, -l/2.0, l, l)];
- [path applyTransform:CGAffineTransformMakeRotation(M_PI * 0.25)];
- [path applyTransform:CGAffineTransformMakeScale(1, 1.6)];
- for (int i=0; i<20; i++) {
- for (int j=0; j<20; j++) {
- float x = i * sqrtf(2) * l - ((j%2==0) ? sqrtf(2) * l * 0.5 : 0);
- float y = j * sqrtf(2) * l * 0.8;
- UIColor *color = ((j % 2) == 0) ? UIColorHex(0xD3C9BF)
- : ((i + j / 2) % 2) == 0 ? UIColorHex(0xC84D49) : UIColorHex(0x282827);
- SKShapeNode *dia = [SKShapeNode shapeNodeWithPath:path.CGPath];
- dia.lineWidth = 0;
- dia.fillColor = color;
- dia.position = CGPointMake(x, y);
- [self.scene addChild:dia];
- }
- }
- }
- - (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
- float l = 50;
- UIBezierPath *path = [UIBezierPath bezierPathWithRect:CGRectMake(-l/2.0, -l/2.0, l, l)];
- [path applyTransform:CGAffineTransformMakeRotation(M_PI * 0.25)];
- [path applyTransform:CGAffineTransformMakeScale(1, 1.6)];
- CGFloat pattern[] = {8,4};
- path = [UIBezierPath bezierPathWithCGPath:CGPathCreateCopyByDashingPath(path.CGPath, nil, 0, pattern, 2)];
- for (int i=0; i<20; i++) {
- for (int j=0; j<20; j++) {
- float x = i * sqrtf(2) * l - ((j%2==1) ? sqrtf(2) * l * 0.5 : 0);
- float y = j * sqrtf(2) * l * 0.8;
- UIColor *color = UIColorHex(0xA8A19D);
- SKShapeNode *dia = [SKShapeNode shapeNodeWithPath:path.CGPath];
- dia.lineWidth = 2;
- dia.strokeColor = color;
- dia.position = CGPointMake(x, y);
- [self.scene addChild:dia];
- }
- }
- }
- @end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement