Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/joshmtucker/OrientationEvents
Module for Framer Studio to handle device orientation events.
https://github.com/joshmtucker/OrientationEvents
Last synced: 3 months ago
JSON representation
Module for Framer Studio to handle device orientation events.
- Host: GitHub
- URL: https://github.com/joshmtucker/OrientationEvents
- Owner: joshmtucker
- Created: 2015-03-23T03:49:06.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2016-07-13T04:33:08.000Z (over 8 years ago)
- Last Synced: 2024-05-07T01:32:58.562Z (6 months ago)
- Language: CoffeeScript
- Size: 1.61 MB
- Stars: 102
- Watchers: 6
- Forks: 15
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- awesome-framer - OrientationEvents - Module for Framer to handle device orientation events. (Modules)
README
# OrientationEvents
Handle device orientation events with Framer Studio. **To SEE and USE values, you must run your prototype in a browser or on a device that supports device orientation events.**![](http://f.cl.ly/items/0w2m1m1z0z1l0a0H3K3O/OrientationEvents.gif)
*Example of device rotation to show larger image, included in repo.*
Code was applied from deviceorientation and devicemotion. View the DeviceOrientationEvents Event Specification for full source.
# Usage
Put the OrientationEvents.coffee file in the /modules folder inside your Framer project. To include in Framer Studio, put the following code at the top of your project:
```coffee
variableName = require "OrientationEvents"
```### Setup
Add event listeners for device orientation and motion.```coffee
variableName.OrientationEvents()# This will print out an error if your device does not support orientation and (or) motion events
```### Values
Values are split up between orientation and motion events and are individual properties. Use them in your code as such:
```coffee
# Orientation variables
variableName.orientation.alpha # Current orientation around Z axis (tilt along perpendicular line to device)
variableName.orientation.beta # Current orientation around X axis (backward/forward tilt)
variableName.orientation.gamma # Current orientation around Y axis (left/right tilt)variableName.orientation.absolute # True if orientation is provided as difference between device coordinate frame and the Earth's coordinate frame. Else false
# Motion variables
variableName.motion.x # Acceleration along X axis
variableName.motion.y # Acceleration along Y axis
variableName.motion.z # Acceleration along Z axisvariableName.motion.gravX # Acceleration along X axis including gravity
variableName.motion.gravY # Acceleration along Y axis including gravity
variableName.motion.gravZ # Acceleration along Z axis including gravityvariableName.motion.rotationRate # Rate of change on all axes. Expressed in degrees per second
variableName.motion.interval # Interval of time in milliseconds that data is obtained from device###
NOTEWhile the values are updated frequently inside the module, you will need to use a setTimeout/setInterval (or build-in for Framer: Utils.delay/Utils.interval) to grab updated values in your project. See ExampleDeviceOrientationEvents.framer to see how I implemented an interval to grab values.
Potentially extending Framer.Events for better support is on my to-do list (something I need to learn).
```## Smoothing
Orientation and motion values are quite jittery in raw form. If you wish to smooth values, I added a means of doing this for both orientation and motion events using a low-pass filter.The way the orientation and motion event properties are computed (with the exception of .absolute, .rotationRate, and .interval) is as follows:
```coffee
# Let's use variable.orientation.alpha (for example). Each property for orientation and motion are set similarly.
# Declared as a local variable at top of the code
filteredAlpha = 0# Later in orientation function...
# filteredAlpha = (event.alpha * exports.smoothOrientation) + (filteredAlpha * (1-exports.smoothing)
```### Change Smoothing
Set smoothing for orientation and motion event values using the following code.
```coffee
# Values set should be between 0 and 1. The higher the value, the less smooth it is.
# Setting to 0 or 1 outputs raw values
# Setting smoothing values affects all properties for each respective variable (documented above).
# If not set in your Framer project, defaults for both are = 1variableName.smoothOrientation = 1
variableName.smoothMotion = .5
```## Example
Download the ExampleDeviceOrientationEvents.framer project to see how to apply values. I used it to build a Facebook Paper-like pan on a photo.
## Questions?
I am available here on GitHub, the FramerJS Facebook Group, and Twitter.