Skip to content

Instantly share code, notes, and snippets.

@antonkartashov
Forked from gk3/3dtouch.coffee
Created October 1, 2015 15:17
Show Gist options
  • Save antonkartashov/0b3fc94705483edf5371 to your computer and use it in GitHub Desktop.
Save antonkartashov/0b3fc94705483edf5371 to your computer and use it in GitHub Desktop.
3D Touch for Framer
# basic setup of layers
test = new Layer width: Screen.width, height: Screen.height
circle = new Layer
circle.center()
forceValue = new Layer width: Screen.width
forceValue.html = "0"
forceValue.style =
textAlign: "center"
lineHeight: forceValue.height + "px"
# make a holder for the current touch
currentTouch = null
# on the beginning of a touch
test.on "touchstart", (e) ->
e.preventDefault()
# trap the new touch event in currentTouch
currentTouch = e
# and at the end of the touch
test.on "touchend", ->
# unset the currentTouch
currentTouch = null
# 100 times a second, we check if theres a touch in progress
Utils.interval 1/100, ->
# and if there is one
if currentTouch
# ask for its latest force value
force = currentTouch.touches[0].force
# and do something with it
forceValue.html = force
newScale = Utils.modulate(force, [0,1], [1,5])
circle.scale = newScale
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment