-
-
Save antonkartashov/0b3fc94705483edf5371 to your computer and use it in GitHub Desktop.
3D Touch for Framer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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