Skip to content

Instantly share code, notes, and snippets.

@edwardsanchez
edwardsanchez / SpringAnimation.swift
Created March 11, 2020 23:47
Spring Animation Playground - Calculating stiffness and damping with a given duration and dampingRatio.
//: A UIKit based Playground for presenting user interface
import UIKit
import PlaygroundSupport
class MyViewController : UIViewController {
override func loadView() {
let view = UIView()
view.backgroundColor = .white
self.view = view
@edwardsanchez
edwardsanchez / Agnostic Operators.swift
Last active November 25, 2017 21:44
A series of operators that work across multiple types
///Shorthand for assigning value only if value is not nil
infix operator ?=
public func ?= <T>(left: inout T, right: T?) {
if let right = right {
left = right
}
}
let fl0 = CGFloat(0)
@edwardsanchez
edwardsanchez / SpringAnimator.swift
Last active March 1, 2024 21:20
Spring Animator
//: Playground - noun: a place where people can play
import UIKit
//Changing values
var initialVelocity: CGFloat = 0
var runningTime: CGFloat = 0
var myProperty: CGFloat = 0
@edwardsanchez
edwardsanchez / EventX and Y on touch device
Created August 30, 2014 23:48
If just using event.x it doesn't work on a touch device and you'll get NaN To get the x and y coordinates you must add event = Events.touchEvent(event) and then call for event.clientX instead of event.x
Dragger = new Layer
x: 0
y: 100
width: 100
height: 100
Dragger.draggable.enabled = true
Dragger.on Events.DragMove, (event)->
event = Events.touchEvent(event)
@edwardsanchez
edwardsanchez / Inertia with Snap
Created August 30, 2014 23:48
Inertia with snap to multiple of a number
LayerWidth = 64
Dragger = new Layer width:LayerWidth*5, y:280, x:0, height: LayerWidth
Dragger.draggable.speedY = 0
Dragger.draggable.enabled = true
Dragger.on Events.DragEnd, ->
# These are two variables you can tweak for different effects
Sliding = true
constant1 = 1000
constant2 = 0
@edwardsanchez
edwardsanchez / Touch Events
Last active August 29, 2015 14:05
Several Event Calls: Touch Start, Touch End, Drag Start, Dragging (continuous calling), Drag End, Hold Star, tHold End, Hold Drag Start, Hold Dragging (continuous), Hold Drag End
layer = new Layer width:200, height:200
layer.draggable.enabled = true
layer.center()
layer.html = "Layer"
isDragging=false
isHolding = false
isHoldingandDragging = false
DragStart = false
@edwardsanchez
edwardsanchez / 0_reuse_code.js
Created August 30, 2014 19:26
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@edwardsanchez
edwardsanchez / Typing Text simulator
Created August 30, 2014 19:21
Simulates string being typed with realistic delays
Name = new Layer width:400, x: 120, y:540, z:4, opacity:1, backgroundColor: "blue"
Name.html = ""
Name.style =
fontSize: '64px'
textAlign: 'center'
fontFamily: 'HelveticaNeue-Light'
lineHeight: '125px'
Name.on Events.TouchStart, ->
#Text to be typed