Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@mzsima
Created December 4, 2016 12:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mzsima/f28d77ce45701a881da102d66842311f to your computer and use it in GitHub Desktop.
Save mzsima/f28d77ce45701a881da102d66842311f to your computer and use it in GitHub Desktop.
argyle pattern
//
// 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
@mzsima
Copy link
Author

mzsima commented Dec 4, 2016

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