Skip to content

Instantly share code, notes, and snippets.

@reccanti
Created January 11, 2020 06:15
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 reccanti/ab9a99de25a1f11af517beb33ff5d116 to your computer and use it in GitHub Desktop.
Save reccanti/ab9a99de25a1f11af517beb33ff5d116 to your computer and use it in GitHub Desktop.
A swift playground with rotating, translucent squares
import SpriteKit
import PlaygroundSupport
let view = SKView()
let scene = SKScene(size: CGSize(width: 100, height: 100))
scene.backgroundColor = #colorLiteral(red: 1.0, green: 1.0, blue: 1.0, alpha: 1.0)
scene.scaleMode = .aspectFit
for i in 1 ... 7 {
let rect = SKShapeNode(rect: CGRect(x: -25, y: -25, width: 50, height: 50))
rect.position = CGPoint(x: 50, y: 50)
rect.fillColor = #colorLiteral(red: 0.5725490196078431, green: 0.0, blue: 0.23137254901960785, alpha: 1.0)
rect.alpha = 0.2
rect.lineWidth = 0
let time = pow(0.8, Double(i)) + 0.2
let rotate = SKAction.rotate(byAngle: 1, duration: time)
rect.run(SKAction.repeatForever(rotate))
scene.addChild(rect)
}
view.presentScene(scene)
PlaygroundPage.current.liveView = view
PlaygroundPage.current.wantsFullScreenLiveView
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment