jaxcore-virtualspin
v0.0.4
Published
A virtual wheel/gear physics simulation for use with Jaxcore Spin
Downloads
8
Readme
Jaxcore VirtualSpin
VirtualSpin is a low-level Matter.js-based physics simulation of a Jaxcore Spin device, exposed as a shared JavaScript library that is used between multiple projects, such as the Jaxcore Spin Simulator and Spin-A-Sketch.
Install and Build
git clone https://github.com/jaxcore/jaxcore-virtualspin.git
cd jaxcore-virtualspin
npm install
npm run build
Run web visualization
Serve ./build/ with any web server. On Mac/Linux if Python is installed type:
cd build
python -m SimpleHTTPServer
For Windows:
cd build
python -m http.server
Then visit http://localhost:8000 to see the Matter.js visualization. Open the web console to view the simulated Jaxcore Spin events (spin, button, knob).
Node Module
The library can be imported into other projects:
npm install jaxcore-virtualspin --save
Capture spin, button, and knob events:
import VirtualSpin from 'jaxcore-virtualspin';
let vspin = new VirtualSpin({
friction: 0.1
});
vspin.on('spin', direction, position) {
console.log('spin', direction, 'position', position);
});
vspin.on('button', pushed) {
console.log('button', pushed);
});
vspin.on('knob', pushed) {
console.log('knob', pushed);
});
vspin.on('rotate', function(angle) {
// precise angle in radians generated by Matter.js
console.log('angle = '+angle);
});
vspin.startSimulation();