Commit df8f7a6e authored by toby's avatar toby

utils

parent 480ab7cc
//
// Utils.swift
// lobo
//
// Created by Toby Padilla on 3/21/15.
// Copyright (c) 2015 Toby Padilla. All rights reserved.
//
import UIKit
func degreesToRadians(degrees: CGFloat) -> CGFloat {
return degrees * (3.1415926 / 180)
}
func CGRectFromOrigin(view: UIView, xPercent: CGFloat, yPercent: CGFloat, width: CGFloat, height: CGFloat) -> CGRect {
let y = view.bounds.size.height * (yPercent / 100)
let x = view.bounds.size.width * (xPercent / 100)
return CGRect(x: x, y: y, width: width, height: height)
}
func randomPercent() -> CGFloat {
return CGFloat(Float(arc4random()) / Float(UINT32_MAX))
}
func randomColor() -> UIColor {
return UIColor.init(red: randomPercent(), green: randomPercent(), blue: randomPercent(), alpha: 1)
}
func randomTransition() -> BGTransition {
// let duration = Double((arc4random() % 5) + 5)
let duration = 2.0
var start = randomColor()
var end = randomColor()
return BGTransition(duration: duration, startColor: start, endColor: end)
}
\ No newline at end of file
......@@ -13,6 +13,7 @@
DA376F141AAD1C4B0071423A /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = DA376F131AAD1C4B0071423A /* Images.xcassets */; };
DA376F171AAD1C4B0071423A /* LaunchScreen.xib in Resources */ = {isa = PBXBuildFile; fileRef = DA376F151AAD1C4B0071423A /* LaunchScreen.xib */; };
DA376F231AAD1C4B0071423A /* loboTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = DA376F221AAD1C4B0071423A /* loboTests.swift */; };
DAAE8A531ABE313400DDFA37 /* Utils.swift in Sources */ = {isa = PBXBuildFile; fileRef = DAAE8A521ABE313400DDFA37 /* Utils.swift */; };
/* End PBXBuildFile section */
/* Begin PBXContainerItemProxy section */
......@@ -36,6 +37,7 @@
DA376F1C1AAD1C4B0071423A /* loboTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = loboTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
DA376F211AAD1C4B0071423A /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
DA376F221AAD1C4B0071423A /* loboTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = loboTests.swift; sourceTree = "<group>"; };
DAAE8A521ABE313400DDFA37 /* Utils.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = Utils.swift; path = ../Utils.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
......@@ -77,6 +79,7 @@
DA376F091AAD1C4B0071423A /* lobo */ = {
isa = PBXGroup;
children = (
DAAE8A521ABE313400DDFA37 /* Utils.swift */,
DA376F0C1AAD1C4B0071423A /* AppDelegate.swift */,
DA376F0E1AAD1C4B0071423A /* ViewController.swift */,
DA376F101AAD1C4B0071423A /* Main.storyboard */,
......@@ -215,6 +218,7 @@
files = (
DA376F0F1AAD1C4B0071423A /* ViewController.swift in Sources */,
DA376F0D1AAD1C4B0071423A /* AppDelegate.swift in Sources */,
DAAE8A531ABE313400DDFA37 /* Utils.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
......
//
// File.swift
// lobo
//
// Created by Toby Padilla on 3/21/15.
// Copyright (c) 2015 Toby Padilla. All rights reserved.
//
import Foundation
......@@ -19,32 +19,6 @@ struct AppState {
var animating: Bool = false
}
func degreesToRadians(degrees: CGFloat) -> CGFloat {
return degrees * (3.1415926 / 180)
}
func CGRectFromOrigin(view: UIView, xPercent: CGFloat, yPercent: CGFloat, width: CGFloat, height: CGFloat) -> CGRect {
let y = view.bounds.size.height * (yPercent / 100)
let x = view.bounds.size.width * (xPercent / 100)
return CGRect(x: x, y: y, width: width, height: height)
}
func randomPercent() -> CGFloat {
return CGFloat(Float(arc4random()) / Float(UINT32_MAX))
}
func randomColor() -> UIColor {
return UIColor.init(red: randomPercent(), green: randomPercent(), blue: randomPercent(), alpha: 1)
}
func randomTransition() -> BGTransition {
// let duration = Double((arc4random() % 5) + 5)
let duration = 2.0
var start = randomColor()
var end = randomColor()
return BGTransition(duration: duration, startColor: start, endColor: end)
}
class ViewController: UIViewController {
var animator: UIDynamicAnimator!
var gravity: UIGravityBehavior!
......
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