Advertisement
Guest User

Untitled

a guest
Dec 4th, 2016
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.62 KB | None | 0 0
  1. //
  2. // ViewController.m
  3. // ArgylePattern
  4. //
  5. // Created by Yusuke Mizushima on 2016/12/04.
  6. // Copyright © 2016 Yusuke Mizushima. All rights reserved.
  7. //
  8.  
  9. #import "ViewController.h"
  10. @import SpriteKit;
  11.  
  12. @interface ViewController ()
  13. @property (nonatomic, weak) SKScene *scene;
  14. @end
  15.  
  16.  
  17. #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]
  18.  
  19. @implementation ViewController
  20.  
  21. - (void)viewDidLoad {
  22. [super viewDidLoad];
  23. [self setupScene];
  24. [self createArgylePattern];
  25. }
  26.  
  27. - (void)setupScene {
  28. SKView *sv = [[SKView alloc] initWithFrame:self.view.bounds];
  29. SKScene *s = [SKScene sceneWithSize:sv.frame.size];
  30. [sv presentScene:s];
  31. [self.view addSubview:sv];
  32. self.scene = s;
  33.  
  34. }
  35.  
  36. - (void)createArgylePattern {
  37. float l = 50;
  38.  
  39. UIBezierPath *path = [UIBezierPath bezierPathWithRect:CGRectMake(-l/2.0, -l/2.0, l, l)];
  40. [path applyTransform:CGAffineTransformMakeRotation(M_PI * 0.25)];
  41. [path applyTransform:CGAffineTransformMakeScale(1, 1.6)];
  42.  
  43. for (int i=0; i<20; i++) {
  44. for (int j=0; j<20; j++) {
  45. float x = i * sqrtf(2) * l - ((j%2==0) ? sqrtf(2) * l * 0.5 : 0);
  46. float y = j * sqrtf(2) * l * 0.8;
  47. UIColor *color = ((j % 2) == 0) ? UIColorHex(0xD3C9BF)
  48. : ((i + j / 2) % 2) == 0 ? UIColorHex(0xC84D49) : UIColorHex(0x282827);
  49. SKShapeNode *dia = [SKShapeNode shapeNodeWithPath:path.CGPath];
  50. dia.lineWidth = 0;
  51. dia.fillColor = color;
  52. dia.position = CGPointMake(x, y);
  53. [self.scene addChild:dia];
  54. }
  55. }
  56. }
  57.  
  58. - (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
  59. float l = 50;
  60.  
  61. UIBezierPath *path = [UIBezierPath bezierPathWithRect:CGRectMake(-l/2.0, -l/2.0, l, l)];
  62. [path applyTransform:CGAffineTransformMakeRotation(M_PI * 0.25)];
  63. [path applyTransform:CGAffineTransformMakeScale(1, 1.6)];
  64. CGFloat pattern[] = {8,4};
  65. path = [UIBezierPath bezierPathWithCGPath:CGPathCreateCopyByDashingPath(path.CGPath, nil, 0, pattern, 2)];
  66.  
  67. for (int i=0; i<20; i++) {
  68. for (int j=0; j<20; j++) {
  69. float x = i * sqrtf(2) * l - ((j%2==1) ? sqrtf(2) * l * 0.5 : 0);
  70. float y = j * sqrtf(2) * l * 0.8;
  71. UIColor *color = UIColorHex(0xA8A19D);
  72. SKShapeNode *dia = [SKShapeNode shapeNodeWithPath:path.CGPath];
  73. dia.lineWidth = 2;
  74. dia.strokeColor = color;
  75. dia.position = CGPointMake(x, y);
  76. [self.scene addChild:dia];
  77. }
  78. }
  79. }
  80.  
  81.  
  82.  
  83. @end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement