Commit 98ce5cac authored by toby's avatar toby

vertical w/ collisions

parent 83ac4df9
......@@ -18,21 +18,28 @@ func CGRectFromOrigin(view: UIView, xPercent: CGFloat, yPercent: CGFloat, width:
return CGRect(x: x, y: y, width: width, height: height)
}
func randFloat() -> CGFloat {
func randPercent() -> CGFloat {
return CGFloat(Float(arc4random()) / Float(UINT32_MAX))
}
class ViewController: UIViewController {
var animator: UIDynamicAnimator!
var gravity: UIGravityBehavior!
var collision: UICollisionBehavior!
override func viewDidLoad() {
super.viewDidLoad()
animator = UIDynamicAnimator(referenceView: view)
gravity = UIGravityBehavior()
gravity.angle = degreesToRadians(180)
gravity.magnitude = CGFloat(0.05)
gravity.angle = degreesToRadians(90)
gravity.magnitude = CGFloat(0.1)
collision = UICollisionBehavior()
collision.translatesReferenceBoundsIntoBoundary = true
animator = UIDynamicAnimator(referenceView: view)
animator.addBehavior(gravity)
animator.addBehavior(collision)
}
override func didReceiveMemoryWarning() {
......@@ -45,9 +52,10 @@ class ViewController: UIViewController {
var block: UIView
block = UIView(frame: CGRect(x: location.x, y: location.y, width: 10, height: 10))
block.center = location
block.backgroundColor = UIColor.init(red: randFloat(), green: randFloat(), blue: randFloat(), alpha: 1)
block.backgroundColor = UIColor.init(red: randPercent(), green: randPercent(), blue: randPercent(), alpha: 1)
view.addSubview(block)
gravity.addItem(block)
collision.addItem(block)
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment