Skip to content

Instantly share code, notes, and snippets.

@andrewdolce
andrewdolce / ViewController.swift
Created March 17, 2016 01:43
Social Tunes Sharer Code Sample: Using the FancyButton
// From Paul's code
@IBOutlet weak var fancyButton: FancyButton!
override func viewDidLoad() {
super.viewDidLoad()
let twitter = FancySubButton(image: UIImage.fancy_twitter()) {
// Do the sharing here
}
@andrewdolce
andrewdolce / FancyButton.swift
Created March 17, 2016 01:42
Social Tunes Sharer Code Sample: Contraints using Cartography
// From Paul's code
constrain(underButtonView, self) { (subButtons, view) -> () in
subButtons.height == view.height
subButtons.width == view.width
subButtons.center == view.center
}
@andrewdolce
andrewdolce / ViewController.swift
Created March 17, 2016 01:30
Social Tunes Sharer Code Sample: Ripple Animation (Part 2)
// From Andrew's code
rippleAnimation.applyToView(bottomView, fromView: tappedView, duration: rippleAnimationDuration)
@andrewdolce
andrewdolce / RippleAnimation.swift
Last active March 17, 2016 01:29
Social Tunes Sharer Code Sample: Ripple Animation (Part 1)
// From Andrew's code
func applyToView(view: UIView, fromView: UIView, duration: NSTimeInterval) {
let rect = view.convertRect(fromView.bounds, fromCoordinateSpace: fromView)
applyToView(view, fromRect: rect, duration: duration)
}
func applyToView(view: UIView, fromRect: CGRect, duration: NSTimeInterval) {
view.addSubview(tintView)
@andrewdolce
andrewdolce / ViewController.swift
Last active March 17, 2016 01:28
Social Tunes Sharer Code Sample: Rounding Corners
// From Andrew's code
override func viewDidLayoutSubviews() {
let halfHeight = CGRectGetHeight(shareContainerView.bounds) / 2;
shareContainerView.layer.cornerRadius = halfHeight
topView.layer.cornerRadius = halfHeight
}
@andrewdolce
andrewdolce / FancyButton.swift
Last active March 17, 2016 01:29
Social Tunes Sharer Code Sample: CGAffineTransform
// From Paul’s code
func titleButtonWasPressed() {
//slide over.
underButtonView.transform = CGAffineTransformMakeTranslation(CGRectGetWidth(bounds), 0)
UIView.animateWithDuration(0.5) { () -> Void in
self.titleButton.transform = CGAffineTransformMakeTranslation(-CGRectGetWidth(self.bounds), 0)
self.underButtonView.transform = CGAffineTransformIdentity
}
@andrewdolce
andrewdolce / ViewController.swift
Last active March 17, 2016 01:29
Social Tunes Sharer Code Sample: Changing Constraints
// From Andrew’s code
private func open() {
// First shift the bottom view all the way to the right
bottomViewLeading.constant = CGRectGetWidth(shareContainerView.bounds)
view.layoutIfNeeded()
// Now animate the views into place
topViewLeading.constant = -CGRectGetWidth(shareContainerView.bounds)
bottomViewLeading.constant = 0
@andrewdolce
andrewdolce / mouselookthrusterai.js
Created February 27, 2013 04:45
call to findTargetTorque()
// Calculate whether we want to go clockwise or
// counter-clockwise to get to target vector, and what the
// desired torque value will be.
var target = ThrusterAIUtils.findTargetTorque(
currentAngularVelocity,
targetAngle,
physics.body.m_invI,
this.maxCCW, -this.maxCW
);
@andrewdolce
andrewdolce / thrusteraiutils.js
Last active December 14, 2015 06:29
weight factors
target[0] = tgtF * weightF;
target[1] = tgtR * weightR;
target[2] = tgtT * weightT;
// ...
current[0] += thruster.localForce[0] * coeff * weightF;
current[1] += thruster.localForce[1] * coeff * weightR;
current[2] += thruster.torque * coeff * weightT;
@andrewdolce
andrewdolce / thrusteraiutils.js
Created February 26, 2013 20:48
iterateOnce result
if ( closest !== Infinity ) {
// Found an adjustment that improves the results, so set the
// coefficient to its new value.
thrusters[ closestIdx ].coeff = closestCoeff;
return false;
} else {
// No adjustment was found, so we have converged.
return true;
}