Advertisement
Guest User

Untitled

a guest
Dec 10th, 2016
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.75 KB | None | 0 0
  1. //
  2. // ViewController.swift
  3. // EllipseWreath
  4. //
  5. // Created by MizushimaYusuke on 2016/12/10.
  6. // Copyright © 2016 MizushimaYusuke. All rights reserved.
  7. //
  8.  
  9. import UIKit
  10. import GameplayKit
  11. import SpriteKit
  12.  
  13. class ViewController: UIViewController {
  14.  
  15. weak var scene: SKScene?
  16.  
  17. override func viewDidLoad() {
  18. super.viewDidLoad()
  19. setupScene()
  20. createEllipse()
  21. }
  22.  
  23. func setupScene() {
  24. let sv = SKView(frame: view.bounds)
  25. let s = SKScene(size: sv.frame.size)
  26. s.backgroundColor = UIColor(hue: 0.6, saturation: 0.1, brightness: 0.1, alpha: 1)
  27. sv.presentScene(s)
  28. view.addSubview(sv)
  29. scene = s
  30. }
  31.  
  32. func createEllipse() {
  33. let n = 40
  34. let dw = CGFloat(M_PI) / CGFloat(n)
  35. for i in 0...n {
  36. let el = SKShapeNode(ellipseIn: CGRect(x: -60, y: -20, width: 120, height: 40))
  37. el.position = CGPoint(x: view.frame.midX, y: view.frame.midY)
  38. el.fillColor = UIColor.clear
  39. let isRed = arc4random_uniform(8) == 0
  40. el.strokeColor = isRed ? UIColor.red : UIColor.green
  41. scene?.addChild(el)
  42. el.zRotation = CGFloat(i) * dw
  43. }
  44. }
  45.  
  46. override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
  47. let n = 40
  48. let dw = CGFloat(M_PI) / CGFloat(n)
  49.  
  50. GKRandomSource.sharedRandom().arrayByShufflingObjects(in: scene!.children)
  51. .enumerated()
  52. .forEach { (i, n) in
  53. (n as! SKNode).run(
  54. SKAction.sequence([
  55. SKAction.rotate(toAngle: CGFloat(M_PI) * 2.0, duration: 1.0),
  56. SKAction.rotate(toAngle: CGFloat(i) * dw, duration: 1.0)
  57. ]))
  58. }
  59. }
  60.  
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement