npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@methodswithclass/accelerometer

v3.3.0

Published

An engine that reads the accelerometer data from the device, calculates position, and applies it to a DOM element.

Downloads

13

Readme

Accelerometer

This package takes acceleromter data from your device, calculates position, and applies it to a DOM element. Applications inlcude gaming, user interface controls, and more.

Change log

Version 3.3.0: request device motion permission bug fix

Usage

It numerically integrates the velocity and position, in real time, from the accelerometer data from the device.

npm install @methodswithclass/accelerometer

import Accelerometer, { ValidStatus } from @methodswithclass/accelerometer

one of these values is returned in a promise from accel.validate()

ValidStatus = {
	valid: 'valid',
	invalid: 'invalid',
	unchecked: 'unchecked',
	denied: 'denied',
	unresponsive: 'unresponsive',
}

parameters for numerical integration process and general motion behavior, defaults are shown

const params = {
	interval: 2, //acceleromter interval in milliseconds
	filterSize: 3, //sampling/smoothing size
	mu: 0.1, //friction
	damp: 0.4, //bounce dampening
	gravity: true, //whether the object responds to tilting of device (true) or only change in position of device (false)
	bounce: true, //whether the object bounces off walls (true), or sticks to the wall (false)
	timeout: 10, // motion timeout with no activity, in seconds
	xDir: 1, //horizonal flip
	yDir: 1, //vertical flip
	factor: 0.008, //sensitivity factor (speed of object)
}

Accelerometer manages several instances by id, subsequent calls return original

const accel = Accelerometer({
	id: "accel", // name of accelerometer instance
	arena: "arenaId", // element id to space to move within
	object: "objectId", //element id of object to be moved
	params, //inject accelerometer parameters
	overrideValidate: false // not all devices have accelerometers, this flag forces the validator to return 'valid', for local development
});

accel.calibrate({ xDir, yDir, factor}); // this is run by default

accel.validate(); // returns a promise with the device validation status, requests permission if necessary (must prompt with a button to request permission)

accel.start(); //start updating position of DOM element based on accelerometer data

accel.stop(); // stop updating position, reset

accel.reset(); // returns object to initial position