Advertisement
Guest User

Untitled

a guest
Sep 29th, 2016
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.58 KB | None | 0 0
  1. //
  2. // ViewController.swift
  3. // SpiralRect
  4. //
  5. // Created by MizushimaYusuke on 2016/09/29.
  6. // Copyright © 2016 MizushimaYusuke. All rights reserved.
  7. //
  8.  
  9. import UIKit
  10. import SpriteKit
  11.  
  12. class ViewController: UIViewController {
  13.  
  14. weak var scene: SKScene?
  15.  
  16. override func viewDidLoad() {
  17. super.viewDidLoad()
  18. setupScene()
  19. createRectangles()
  20. }
  21.  
  22. func setupScene() {
  23. let sv = SKView(frame: view.bounds)
  24. let s = SKScene(size: sv.frame.size)
  25. sv.presentScene(s)
  26. view.addSubview(sv)
  27. scene = s
  28. }
  29.  
  30. func createRectangles() {
  31. var preNode: SKNode?
  32. let s = 30.0
  33. for i in 0...20 {
  34. let r = SKSpriteNode(color: UIColor.yellow, size: CGSize(width: s, height: s))
  35.  
  36. if i % 2 == 0 {
  37. if i != 0 {
  38. r.position = CGPoint(x: -s * 0.8, y: -s * 0.8)
  39. }
  40. r.anchorPoint = CGPoint(x: 0.1, y: 0.1)
  41. r.run(SKAction.repeatForever(SKAction.rotate(byAngle: CGFloat(M_PI), duration: 10.0)))
  42. } else {
  43. r.position = CGPoint(x: s * 0.8, y: s * 0.8)
  44. r.anchorPoint = CGPoint(x: 0.9, y: 0.9)
  45.  
  46. r.run(SKAction.repeatForever(SKAction.rotate(byAngle: -CGFloat(M_PI), duration: 5.0)))
  47. }
  48. if preNode != nil {
  49. preNode?.addChild(r)
  50. } else {
  51. r.position = CGPoint(x: view.frame.midX, y: view.frame.midY)
  52. scene?.addChild(r)
  53. }
  54. preNode = r
  55. }
  56. }
  57.  
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement