Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // ViewController.swift
- // EllipseWreath
- //
- // Created by MizushimaYusuke on 2016/12/10.
- // Copyright © 2016 MizushimaYusuke. All rights reserved.
- //
- import UIKit
- import GameplayKit
- import SpriteKit
- class ViewController: UIViewController {
- weak var scene: SKScene?
- override func viewDidLoad() {
- super.viewDidLoad()
- setupScene()
- createEllipse()
- }
- func setupScene() {
- let sv = SKView(frame: view.bounds)
- let s = SKScene(size: sv.frame.size)
- s.backgroundColor = UIColor(hue: 0.6, saturation: 0.1, brightness: 0.1, alpha: 1)
- sv.presentScene(s)
- view.addSubview(sv)
- scene = s
- }
- func createEllipse() {
- let n = 40
- let dw = CGFloat(M_PI) / CGFloat(n)
- for i in 0...n {
- let el = SKShapeNode(ellipseIn: CGRect(x: -60, y: -20, width: 120, height: 40))
- el.position = CGPoint(x: view.frame.midX, y: view.frame.midY)
- el.fillColor = UIColor.clear
- let isRed = arc4random_uniform(8) == 0
- el.strokeColor = isRed ? UIColor.red : UIColor.green
- scene?.addChild(el)
- el.zRotation = CGFloat(i) * dw
- }
- }
- override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
- let n = 40
- let dw = CGFloat(M_PI) / CGFloat(n)
- GKRandomSource.sharedRandom().arrayByShufflingObjects(in: scene!.children)
- .enumerated()
- .forEach { (i, n) in
- (n as! SKNode).run(
- SKAction.sequence([
- SKAction.rotate(toAngle: CGFloat(M_PI) * 2.0, duration: 1.0),
- SKAction.rotate(toAngle: CGFloat(i) * dw, duration: 1.0)
- ]))
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement