Giter Club home page Giter Club logo

sensor.framer's Introduction

Mobile Sensor

A Framer Studio module for deivce sensor to your project.

Demo - Orientation Sensor
Demo - Motion Sensor

check it on the device that provides the motion sensor (mobile).


Preview

https://vimeo.com/196395840 - Full version Preview

Sensor module for Framer


Features

  • Multiple browser supported
  • Orientation Sensor
  • Motion Sensor

Installation

Copy the "module" folder and paste it into your prototype folder

More info about modules for Framer Studio: FramerJS Docs - Modules


Expansion


Usage

Context

Constant

Context.SENSOR_SERVICE

Sensor service

Method

getSystemService(service)

Get system service

Parameters
  • service [string] : service

Sensor

Constant

Sensor.TYPE_ORIENTATION

Orientation sensor

Sensor.TYPE_MOTION

Motion sensor

Properties

Sensor.smooth

[Number] Coefficient of sensor transfer value

Since the sensor of the device reacts very sensitively, if the value transmitted from the sensor is used as it is, the small movement of the device will cause it to shake or vibrate. You can adjust the value to obtain a smoothly tuned value

Events

Change

When the sensor value changes

Events.Change - New sensor value.

Shortcut

Sensor.onChange(orientation or motion)

Parameters
  • orientation [Object] - Orientation values (Orientation Sensor)

    • alpha [Double] - Z-axis rotation
    • beta [Double] - X-axis rotation
    • gamma [Double] - Y-axis rotation
  • motion [Object] - Motion values (Motion Sensor)

    • acceleration
      • x [Double]
      • y [Double]
      • z [Double]
    • accelerationIncludingGravity
      • x [Double]
      • y [Double]
      • z [Double]
    • rotationRate
      • alpha [Double]
      • beta [Double]
      • gamma [Double]
      • interval [Double]

More info about Device Orientation Event : W3C Device Orientation Event Specification


Sample

Prepare

Set background color

Screen.backgroundColor = "gray"

Create cube

#
SIZE = 200
# Cube
cube = new Layer
    point: Align.center
    size: SIZE
    rotationY: 0, rotationX: -30
    style: 
        transformStyle: "preserve-3d"
        "-webkit-transform-style": "preserve-3d"
    backgroundColor: ""

# Face properties
properties = 
    size: SIZE
    style: 
        fontSize: "20px", fontWeight: "500", lineHeight: "#{SIZE}px"
        textAlign: "center", textTransform: "uppercase"
        boxShadow: "inset 0 0 30px rgba(0,0,0,0.2)"
    color: "rgba(0,0,0,.5)"
    backgroundColor: "rgba(255,255,255,1.1)"
    parent: cube
    
# Front
front = new Layer _.extend _.clone(properties), html: "front", z: 100
# Back
back = new Layer _.extend _.clone(properties), html: "back", z: -100, rotationY: 180
# Top
top = new Layer _.extend _.clone(properties), html: "top", rotationX: 90, y: -100
# Bottom
bottom = new Layer _.extend _.clone(properties), html: "bottom", rotationX: -90, y: 100
# Left
left = new Layer _.extend _.clone(properties), html: "left", rotationY: -90, x: -100
# RightSe
right = new Layer _.extend _.clone(properties), html: "right", rotationY: 90, x: 100

Use module

Orientation sensor

# Module
require 'System'
# Sensor manager
sensorManager = getSystemService(Context.SENSOR_SERVICE)
# Sensor : Orientation
sensorOrientation = sensorManager.getDefaultSensor(Sensor.TYPE_ORIENTATION)
if sensorOrientation
    sensorOrientation.smooth = 0.1
    sensorOrientation.onChange (event) ->
        cube.rotationX = -(event.beta) * 2 + 60
        cube.rotationY = (event.gamma) * 2

or

Motion sensor

# Module
require 'System'
# Sensor manager
sensorManager = getSystemService(Context.SENSOR_SERVICE)
# Sensor : Motion
sensorMotion = sensorManager.getDefaultSensor(Sensor.TYPE_MOTION)
if sensorMotion
    sensorMotion.smooth = 0.005
    sensorMotion.onChange (event) ->
        cube.rotationX -= event.rotationRate.alpha
        cube.rotationY += event.rotationRate.beta

sensor.framer's People

Contributors

threeword avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.