際際滷

際際滷Share a Scribd company logo
by John Tubert

LeapMotion
Communicating with other browsers
and adding graphics (and maybe
moving some 3d shape)
Communicating with other browsers
Technologies used:
 Node.js (with socket.io and express)
 Hosted on Heroku
Server code
var express = require('express');

io.sockets.on('connection', function (socket) {

var app = express.createServer();

socket.on('frame',function(data){
socket.broadcast.emit('frame', data);

var io = require('socket.io').listen(app), fs = require('fs');

});
});

io.configure(function () {
io.set("transports", ["xhr-polling"]);
io.set("polling duration", 10);
});

app.use(express.static(__dirname + '/static'));

var port = process.env.PORT || 5000;
app.listen(port, function() {
console.log("Listening on " + port);
});
Front end code
var socket = io.connect(window.location.host.toString());

if(socket){

...

socket.on('frame', function (data) {

Leap.loop(function(frame) {

console.log("data: ",data);

Controller.getFrame(frame);

Controller.getFrame(data);

if(socket){
var obj = {};
obj.pointables = {};
obj.pointables.length = frame.pointables.length;
obj.hands = [];
obj.hands[0] = {};
obj.hands[0].palmPosition = [];
obj.hands[0].palmPosition[0] = {};
obj.hands[0].palmPosition[1] = {};
obj.hands[0].palmPosition[1] = frame.hands[0].palmPosition[1];
socket.emit("frame",obj);
}
});
...

});
}
Graphics
Using http://paperjs.org/, a canvas
framework.
Graphics - create/update
//CREATE -------

//UPDATE ON FRAME --------

var a = x*Math.floor(360/6);

paper.view.onFrame = function(event) {

var angle = (a*dtr);

graphicsArr[id]["angle"]+=1;

var x = (gRadius*Math.cos(angle));

var angle = (graphicsArr[id]["angle"]*dtr);

var y = (gRadius*Math.sin(angle));

var x = (gRadius*Math.cos(angle));

graphicsArr[id] = new paper.Path.Rectangle([x+xOffset, y+yOffset], [40, 40]);

var y = (gRadius*Math.sin(angle));

graphicsArr[id]["angle"] = a;

graphicsArr[id].position = [x+xOffset,y+yOffset];

graphicsArr[id]["text"] = new paper.PointText({

graphicsArr[id]["text"].position = [x+xOffset,y+yOffset+40];

point: [x+xOffset,y+yOffset],
justification: 'left',
fontSize: 13,
fillColor: 'white'
});

graphicsArr[id]["text"].content = id;
graphicsArr[id].strokeColor = '#ffffff';
graphicsArr[id].fillColor = 'black';
paper.view.draw();

}
Graphics - in main.js
Loop.prototype = {

Graphics.createShape(audio.id,counter);
}
play : function(id) {
if (id !== this.id) { this.audio.play(); } else { this.changeState(false); }
Graphics.updateColor(id,"red");
},
pause : function(id) {
Graphics.updateColor(id,"black");
this.changeState(true);
},
...
setGlobalVolume : function(frame, pointables){
...
Graphics.updateVolume(Math.round(volOutput*100));
}
Demo
http://jtubert-leap.herokuapp.com/
Controlling a 3d shape
 3d cube using CSS3
 Controlling it using Leaps palm position
var hand = frame.hands[0];
yVal = hand.palmPosition;
var volChangeY = parseFloat(yVal[0].toFixed(1));
volOutputY = volChangeY/yThreshold;
...
var x = volOutputX*360;
var y = volOutputY*360;
var z = volOutputZ*360;
$('#cube').css('-webkit-transform', 'rotate3d('+x+', '+y+', '+z+', '+z+'deg)');
Demo - cube
http://jtubert-leap.herokuapp.com/cube.html
Thanks
https://github.com/jtubert/leap
Ad

Recommended

C++ AMP れ 覦
C++ AMP れ 覦
覈 蟾
Kinect de-theremin
Kinect de-theremin
Kazuyuki Honda
The PDP-10 - and me
The PDP-10 - and me
Bj淡rn Hell Larsen
Java lejos-multithreading
Java lejos-multithreading
Mr. Chanuwan
Eulode
Eulode
shah1230
LvivPy4 - Threading vs asyncio
LvivPy4 - Threading vs asyncio
Roman Rader
Libre Office Impress Lesson 3: Adding and Formatting pictures
Libre Office Impress Lesson 3: Adding and Formatting pictures
Smart Chicago Collaborative
3 d shapes 2
3 d shapes 2
Abdo Abdo
Socket.io
Socket.io
Antonio Terreno
soft-shake.ch - Hands on Node.js
soft-shake.ch - Hands on Node.js
soft-shake.ch
node.js practical guide to serverside javascript
node.js practical guide to serverside javascript
Eldar Djafarov
Mobile webapplication development
Mobile webapplication development
Ganesh Gembali
NodeJS
NodeJS
Alok Guha
JS everywhere 2011
JS everywhere 2011
Oleg Podsechin
Nodejs and WebSockets
Nodejs and WebSockets
Gonzalo Ayuso
Node worshop Realtime - Socket.io
Node worshop Realtime - Socket.io
Caesar Chi
mobl
mobl
zefhemel
Building Web Apps with Express
Building Web Apps with Express
Aaron Stannard
Writing robust Node.js applications
Writing robust Node.js applications
Tom Croucher
Nest in Peace
Nest in Peace
Gil Steiner
Event-driven IO server-side JavaScript environment based on V8 Engine
Event-driven IO server-side JavaScript environment based on V8 Engine
Ricardo Silva
Switch to Backend 2023 | Day 1 Part 2
Switch to Backend 2023 | Day 1 Part 2
Google Developer Students Club NIT Silchar
Workshop 4: NodeJS. Express Framework & MongoDB.
Workshop 4: NodeJS. Express Framework & MongoDB.
Visual Engineering
Kraken Front-Trends
Kraken Front-Trends
PayPal
NodeJs
NodeJs
dizabl
FAESA CONENCO 2013: Sencha Touch 2 + PhoneGap
FAESA CONENCO 2013: Sencha Touch 2 + PhoneGap
Loiane Groner
express-express-express-express-express-
express-express-express-express-express-
pransu471shdp
The Death of a Mouse
The Death of a Mouse
Geert Bevin
Sibling rivalry tech vs. philosophy on bias in ai
Sibling rivalry tech vs. philosophy on bias in ai
John Tubert
Sibling rivalry tech vs. philosophy on bias & AI
Sibling rivalry tech vs. philosophy on bias & AI
John Tubert

More Related Content

Similar to LeapMotion (20)

Socket.io
Socket.io
Antonio Terreno
soft-shake.ch - Hands on Node.js
soft-shake.ch - Hands on Node.js
soft-shake.ch
node.js practical guide to serverside javascript
node.js practical guide to serverside javascript
Eldar Djafarov
Mobile webapplication development
Mobile webapplication development
Ganesh Gembali
NodeJS
NodeJS
Alok Guha
JS everywhere 2011
JS everywhere 2011
Oleg Podsechin
Nodejs and WebSockets
Nodejs and WebSockets
Gonzalo Ayuso
Node worshop Realtime - Socket.io
Node worshop Realtime - Socket.io
Caesar Chi
mobl
mobl
zefhemel
Building Web Apps with Express
Building Web Apps with Express
Aaron Stannard
Writing robust Node.js applications
Writing robust Node.js applications
Tom Croucher
Nest in Peace
Nest in Peace
Gil Steiner
Event-driven IO server-side JavaScript environment based on V8 Engine
Event-driven IO server-side JavaScript environment based on V8 Engine
Ricardo Silva
Switch to Backend 2023 | Day 1 Part 2
Switch to Backend 2023 | Day 1 Part 2
Google Developer Students Club NIT Silchar
Workshop 4: NodeJS. Express Framework & MongoDB.
Workshop 4: NodeJS. Express Framework & MongoDB.
Visual Engineering
Kraken Front-Trends
Kraken Front-Trends
PayPal
NodeJs
NodeJs
dizabl
FAESA CONENCO 2013: Sencha Touch 2 + PhoneGap
FAESA CONENCO 2013: Sencha Touch 2 + PhoneGap
Loiane Groner
express-express-express-express-express-
express-express-express-express-express-
pransu471shdp
The Death of a Mouse
The Death of a Mouse
Geert Bevin
soft-shake.ch - Hands on Node.js
soft-shake.ch - Hands on Node.js
soft-shake.ch
node.js practical guide to serverside javascript
node.js practical guide to serverside javascript
Eldar Djafarov
Mobile webapplication development
Mobile webapplication development
Ganesh Gembali
Nodejs and WebSockets
Nodejs and WebSockets
Gonzalo Ayuso
Node worshop Realtime - Socket.io
Node worshop Realtime - Socket.io
Caesar Chi
Building Web Apps with Express
Building Web Apps with Express
Aaron Stannard
Writing robust Node.js applications
Writing robust Node.js applications
Tom Croucher
Nest in Peace
Nest in Peace
Gil Steiner
Event-driven IO server-side JavaScript environment based on V8 Engine
Event-driven IO server-side JavaScript environment based on V8 Engine
Ricardo Silva
Workshop 4: NodeJS. Express Framework & MongoDB.
Workshop 4: NodeJS. Express Framework & MongoDB.
Visual Engineering
Kraken Front-Trends
Kraken Front-Trends
PayPal
NodeJs
NodeJs
dizabl
FAESA CONENCO 2013: Sencha Touch 2 + PhoneGap
FAESA CONENCO 2013: Sencha Touch 2 + PhoneGap
Loiane Groner
express-express-express-express-express-
express-express-express-express-express-
pransu471shdp
The Death of a Mouse
The Death of a Mouse
Geert Bevin

More from John Tubert (8)

Sibling rivalry tech vs. philosophy on bias in ai
Sibling rivalry tech vs. philosophy on bias in ai
John Tubert
Sibling rivalry tech vs. philosophy on bias & AI
Sibling rivalry tech vs. philosophy on bias & AI
John Tubert
Extreme Danger of bias in Artificial Inteligence
Extreme Danger of bias in Artificial Inteligence
John Tubert
Sketchio presentation at Parse Developer meetup
Sketchio presentation at Parse Developer meetup
John Tubert
Browserless javascript testing
Browserless javascript testing
John Tubert
Drawing room experiment
Drawing room experiment
John Tubert
Parse.com
Parse.com
John Tubert
Bunch of random tech things
Bunch of random tech things
John Tubert
Sibling rivalry tech vs. philosophy on bias in ai
Sibling rivalry tech vs. philosophy on bias in ai
John Tubert
Sibling rivalry tech vs. philosophy on bias & AI
Sibling rivalry tech vs. philosophy on bias & AI
John Tubert
Extreme Danger of bias in Artificial Inteligence
Extreme Danger of bias in Artificial Inteligence
John Tubert
Sketchio presentation at Parse Developer meetup
Sketchio presentation at Parse Developer meetup
John Tubert
Browserless javascript testing
Browserless javascript testing
John Tubert
Drawing room experiment
Drawing room experiment
John Tubert
Bunch of random tech things
Bunch of random tech things
John Tubert
Ad

Recently uploaded (20)

9-1-1 Addressing: End-to-End Automation Using FME
9-1-1 Addressing: End-to-End Automation Using FME
Safe Software
Connecting Data and Intelligence: The Role of FME in Machine Learning
Connecting Data and Intelligence: The Role of FME in Machine Learning
Safe Software
Powering Multi-Page Web Applications Using Flow Apps and FME Data Streaming
Powering Multi-Page Web Applications Using Flow Apps and FME Data Streaming
Safe Software
Securing AI - There Is No Try, Only Do!.pdf
Securing AI - There Is No Try, Only Do!.pdf
Priyanka Aash
Creating Inclusive Digital Learning with AI: A Smarter, Fairer Future
Creating Inclusive Digital Learning with AI: A Smarter, Fairer Future
Impelsys Inc.
Key Requirements to Successfully Implement Generative AI in Edge DevicesOpt...
Key Requirements to Successfully Implement Generative AI in Edge DevicesOpt...
Edge AI and Vision Alliance
Crypto Super 500 - 14th Report - June2025.pdf
Crypto Super 500 - 14th Report - June2025.pdf
Stephen Perrenod
Python Conference Singapore - 19 Jun 2025
Python Conference Singapore - 19 Jun 2025
ninefyi
10 Key Challenges for AI within the EU Data Protection Framework.pdf
10 Key Challenges for AI within the EU Data Protection Framework.pdf
Priyanka Aash
OpenACC and Open Hackathons Monthly Highlights June 2025
OpenACC and Open Hackathons Monthly Highlights June 2025
OpenACC
The Future of AI Agent Development Trends to Watch.pptx
The Future of AI Agent Development Trends to Watch.pptx
Lisa ward
"Database isolation: how we deal with hundreds of direct connections to the d...
"Database isolation: how we deal with hundreds of direct connections to the d...
Fwdays
Improving Data Integrity: Synchronization between EAM and ArcGIS Utility Netw...
Improving Data Integrity: Synchronization between EAM and ArcGIS Utility Netw...
Safe Software
FIDO Seminar: Evolving Landscape of Post-Quantum Cryptography.pptx
FIDO Seminar: Evolving Landscape of Post-Quantum Cryptography.pptx
FIDO Alliance
Oh, the Possibilities - Balancing Innovation and Risk with Generative AI.pdf
Oh, the Possibilities - Balancing Innovation and Risk with Generative AI.pdf
Priyanka Aash
Enhance GitHub Copilot using MCP - Enterprise version.pdf
Enhance GitHub Copilot using MCP - Enterprise version.pdf
Nilesh Gule
GenAI Opportunities and Challenges - Where 370 Enterprises Are Focusing Now.pdf
GenAI Opportunities and Challenges - Where 370 Enterprises Are Focusing Now.pdf
Priyanka Aash
ReSTIR [DI]: Spatiotemporal reservoir resampling for real-time ray tracing ...
ReSTIR [DI]: Spatiotemporal reservoir resampling for real-time ray tracing ...
revolcs10
FIDO Seminar: Authentication for a Billion Consumers - Amazon.pptx
FIDO Seminar: Authentication for a Billion Consumers - Amazon.pptx
FIDO Alliance
OpenPOWER Foundation & Open-Source Core Innovations
OpenPOWER Foundation & Open-Source Core Innovations
IBM
9-1-1 Addressing: End-to-End Automation Using FME
9-1-1 Addressing: End-to-End Automation Using FME
Safe Software
Connecting Data and Intelligence: The Role of FME in Machine Learning
Connecting Data and Intelligence: The Role of FME in Machine Learning
Safe Software
Powering Multi-Page Web Applications Using Flow Apps and FME Data Streaming
Powering Multi-Page Web Applications Using Flow Apps and FME Data Streaming
Safe Software
Securing AI - There Is No Try, Only Do!.pdf
Securing AI - There Is No Try, Only Do!.pdf
Priyanka Aash
Creating Inclusive Digital Learning with AI: A Smarter, Fairer Future
Creating Inclusive Digital Learning with AI: A Smarter, Fairer Future
Impelsys Inc.
Key Requirements to Successfully Implement Generative AI in Edge DevicesOpt...
Key Requirements to Successfully Implement Generative AI in Edge DevicesOpt...
Edge AI and Vision Alliance
Crypto Super 500 - 14th Report - June2025.pdf
Crypto Super 500 - 14th Report - June2025.pdf
Stephen Perrenod
Python Conference Singapore - 19 Jun 2025
Python Conference Singapore - 19 Jun 2025
ninefyi
10 Key Challenges for AI within the EU Data Protection Framework.pdf
10 Key Challenges for AI within the EU Data Protection Framework.pdf
Priyanka Aash
OpenACC and Open Hackathons Monthly Highlights June 2025
OpenACC and Open Hackathons Monthly Highlights June 2025
OpenACC
The Future of AI Agent Development Trends to Watch.pptx
The Future of AI Agent Development Trends to Watch.pptx
Lisa ward
"Database isolation: how we deal with hundreds of direct connections to the d...
"Database isolation: how we deal with hundreds of direct connections to the d...
Fwdays
Improving Data Integrity: Synchronization between EAM and ArcGIS Utility Netw...
Improving Data Integrity: Synchronization between EAM and ArcGIS Utility Netw...
Safe Software
FIDO Seminar: Evolving Landscape of Post-Quantum Cryptography.pptx
FIDO Seminar: Evolving Landscape of Post-Quantum Cryptography.pptx
FIDO Alliance
Oh, the Possibilities - Balancing Innovation and Risk with Generative AI.pdf
Oh, the Possibilities - Balancing Innovation and Risk with Generative AI.pdf
Priyanka Aash
Enhance GitHub Copilot using MCP - Enterprise version.pdf
Enhance GitHub Copilot using MCP - Enterprise version.pdf
Nilesh Gule
GenAI Opportunities and Challenges - Where 370 Enterprises Are Focusing Now.pdf
GenAI Opportunities and Challenges - Where 370 Enterprises Are Focusing Now.pdf
Priyanka Aash
ReSTIR [DI]: Spatiotemporal reservoir resampling for real-time ray tracing ...
ReSTIR [DI]: Spatiotemporal reservoir resampling for real-time ray tracing ...
revolcs10
FIDO Seminar: Authentication for a Billion Consumers - Amazon.pptx
FIDO Seminar: Authentication for a Billion Consumers - Amazon.pptx
FIDO Alliance
OpenPOWER Foundation & Open-Source Core Innovations
OpenPOWER Foundation & Open-Source Core Innovations
IBM
Ad

LeapMotion

  • 1. by John Tubert LeapMotion Communicating with other browsers and adding graphics (and maybe moving some 3d shape)
  • 2. Communicating with other browsers Technologies used: Node.js (with socket.io and express) Hosted on Heroku
  • 3. Server code var express = require('express'); io.sockets.on('connection', function (socket) { var app = express.createServer(); socket.on('frame',function(data){ socket.broadcast.emit('frame', data); var io = require('socket.io').listen(app), fs = require('fs'); }); }); io.configure(function () { io.set("transports", ["xhr-polling"]); io.set("polling duration", 10); }); app.use(express.static(__dirname + '/static')); var port = process.env.PORT || 5000; app.listen(port, function() { console.log("Listening on " + port); });
  • 4. Front end code var socket = io.connect(window.location.host.toString()); if(socket){ ... socket.on('frame', function (data) { Leap.loop(function(frame) { console.log("data: ",data); Controller.getFrame(frame); Controller.getFrame(data); if(socket){ var obj = {}; obj.pointables = {}; obj.pointables.length = frame.pointables.length; obj.hands = []; obj.hands[0] = {}; obj.hands[0].palmPosition = []; obj.hands[0].palmPosition[0] = {}; obj.hands[0].palmPosition[1] = {}; obj.hands[0].palmPosition[1] = frame.hands[0].palmPosition[1]; socket.emit("frame",obj); } }); ... }); }
  • 6. Graphics - create/update //CREATE ------- //UPDATE ON FRAME -------- var a = x*Math.floor(360/6); paper.view.onFrame = function(event) { var angle = (a*dtr); graphicsArr[id]["angle"]+=1; var x = (gRadius*Math.cos(angle)); var angle = (graphicsArr[id]["angle"]*dtr); var y = (gRadius*Math.sin(angle)); var x = (gRadius*Math.cos(angle)); graphicsArr[id] = new paper.Path.Rectangle([x+xOffset, y+yOffset], [40, 40]); var y = (gRadius*Math.sin(angle)); graphicsArr[id]["angle"] = a; graphicsArr[id].position = [x+xOffset,y+yOffset]; graphicsArr[id]["text"] = new paper.PointText({ graphicsArr[id]["text"].position = [x+xOffset,y+yOffset+40]; point: [x+xOffset,y+yOffset], justification: 'left', fontSize: 13, fillColor: 'white' }); graphicsArr[id]["text"].content = id; graphicsArr[id].strokeColor = '#ffffff'; graphicsArr[id].fillColor = 'black'; paper.view.draw(); }
  • 7. Graphics - in main.js Loop.prototype = { Graphics.createShape(audio.id,counter); } play : function(id) { if (id !== this.id) { this.audio.play(); } else { this.changeState(false); } Graphics.updateColor(id,"red"); }, pause : function(id) { Graphics.updateColor(id,"black"); this.changeState(true); }, ... setGlobalVolume : function(frame, pointables){ ... Graphics.updateVolume(Math.round(volOutput*100)); }
  • 9. Controlling a 3d shape 3d cube using CSS3 Controlling it using Leaps palm position var hand = frame.hands[0]; yVal = hand.palmPosition; var volChangeY = parseFloat(yVal[0].toFixed(1)); volOutputY = volChangeY/yThreshold; ... var x = volOutputX*360; var y = volOutputY*360; var z = volOutputZ*360; $('#cube').css('-webkit-transform', 'rotate3d('+x+', '+y+', '+z+', '+z+'deg)');