Skip to content

Instantly share code, notes, and snippets.

@mzsima
Created October 6, 2017 15:05
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/9b3321e7f3bd5d969c7fd2f52a043c4b to your computer and use it in GitHub Desktop.
Save mzsima/9b3321e7f3bd5d969c7fd2f52a043c4b to your computer and use it in GitHub Desktop.
othello board
//
// ViewController.m
// OthelloBoard
//
// Created by MizushimaYusuke on 2017/10/06.
// Copyright © 2017 MizushimaYusuke. All rights reserved.
//
#import "ViewController.h"
@import SceneKit;
@interface ViewController ()
@property (nonatomic, weak) SCNView *sceneView;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
[self setupScene];
[self createBoard];
}
- (void)setupScene {
SCNView *sv = [[SCNView alloc] initWithFrame:self.view.bounds];
sv.backgroundColor = [UIColor colorWithHue:0.3 saturation:0.9 brightness:0.6 alpha:1];
sv.scene = [SCNScene scene];
sv.allowsCameraControl = YES;
sv.autoenablesDefaultLighting = YES;
[self.view addSubview:sv];
self.sceneView = sv;
}
- (void)createBoard {
for (int i=0; i<8; i++) {
for (int j=0; j<8; j++) {
SCNNode *n = [self createOthello];
n.position = SCNVector3Make(2.2 * i, 0, 2.2 * j);
}
}
}
- (SCNNode *)createOthello {
SCNNode *disk = [SCNNode node];
disk.name = @"disk";
[self.sceneView.scene.rootNode addChildNode:disk];
SCNCylinder *black = [SCNCylinder cylinderWithRadius:1 height:0.1];
black.firstMaterial.diffuse.contents = [UIColor colorWithWhite:0.1 alpha:1];
SCNCylinder *white = [SCNCylinder cylinderWithRadius:1 height:0.1];
white.firstMaterial.diffuse.contents = [UIColor whiteColor];
SCNNode *bnode = [SCNNode nodeWithGeometry: black];
bnode.position = SCNVector3Make(0, 0.05, 0);
[disk addChildNode:bnode];
SCNNode *wnode = [SCNNode nodeWithGeometry: white];
wnode.position = SCNVector3Make(0, -0.05, 0);
[disk addChildNode:wnode];
return disk;
}
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
[[self.sceneView.scene.rootNode childNodes] enumerateObjectsUsingBlock:^(SCNNode * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
if (arc4random_uniform(10) == 0) {
[obj runAction:[SCNAction rotateByX:M_PI y:0 z:0 duration:0.5]];
}
}];
}
@end
@mzsima
Copy link
Author

mzsima commented Oct 6, 2017

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