SlideShare a Scribd company logo
1 of 11
Download to read offline
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 Leap’s 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

More Related Content

Similar to LeapMotion

node.js practical guide to serverside javascript
node.js practical guide to serverside javascriptnode.js practical guide to serverside javascript
node.js practical guide to serverside javascript
Eldar Djafarov
 
Mobile webapplication development
Mobile webapplication developmentMobile webapplication development
Mobile webapplication development
Ganesh Gembali
 
Writing robust Node.js applications
Writing robust Node.js applicationsWriting robust Node.js applications
Writing robust Node.js applications
Tom Croucher
 
Alexey Orlenko ''High-performance IPC and RPC for microservices and apps''
Alexey Orlenko ''High-performance IPC and RPC for microservices and apps''Alexey Orlenko ''High-performance IPC and RPC for microservices and apps''
Alexey Orlenko ''High-performance IPC and RPC for microservices and apps''
OdessaJS Conf
 

Similar to LeapMotion (20)

Socket.io
Socket.ioSocket.io
Socket.io
 
soft-shake.ch - Hands on Node.js
soft-shake.ch - Hands on Node.jssoft-shake.ch - Hands on Node.js
soft-shake.ch - Hands on Node.js
 
node.js practical guide to serverside javascript
node.js practical guide to serverside javascriptnode.js practical guide to serverside javascript
node.js practical guide to serverside javascript
 
Mobile webapplication development
Mobile webapplication developmentMobile webapplication development
Mobile webapplication development
 
NodeJS
NodeJSNodeJS
NodeJS
 
JS everywhere 2011
JS everywhere 2011JS everywhere 2011
JS everywhere 2011
 
Nodejs and WebSockets
Nodejs and WebSocketsNodejs and WebSockets
Nodejs and WebSockets
 
Node worshop Realtime - Socket.io
Node worshop Realtime - Socket.ioNode worshop Realtime - Socket.io
Node worshop Realtime - Socket.io
 
mobl
moblmobl
mobl
 
Building Web Apps with Express
Building Web Apps with ExpressBuilding Web Apps with Express
Building Web Apps with Express
 
Writing robust Node.js applications
Writing robust Node.js applicationsWriting robust Node.js applications
Writing robust Node.js applications
 
Nest in Peace
Nest in PeaceNest in Peace
Nest in Peace
 
Event-driven IO server-side JavaScript environment based on V8 Engine
Event-driven IO server-side JavaScript environment based on V8 EngineEvent-driven IO server-side JavaScript environment based on V8 Engine
Event-driven IO server-side JavaScript environment based on V8 Engine
 
Switch to Backend 2023 | Day 1 Part 2
Switch to Backend 2023 | Day 1 Part 2Switch to Backend 2023 | Day 1 Part 2
Switch to Backend 2023 | Day 1 Part 2
 
Workshop 4: NodeJS. Express Framework & MongoDB.
Workshop 4: NodeJS. Express Framework & MongoDB.Workshop 4: NodeJS. Express Framework & MongoDB.
Workshop 4: NodeJS. Express Framework & MongoDB.
 
Kraken Front-Trends
Kraken Front-TrendsKraken Front-Trends
Kraken Front-Trends
 
NodeJs
NodeJsNodeJs
NodeJs
 
FAESA CONENCO 2013: Sencha Touch 2 + PhoneGap
FAESA CONENCO 2013: Sencha Touch 2 + PhoneGapFAESA CONENCO 2013: Sencha Touch 2 + PhoneGap
FAESA CONENCO 2013: Sencha Touch 2 + PhoneGap
 
The Death of a Mouse
The Death of a MouseThe Death of a Mouse
The Death of a Mouse
 
Alexey Orlenko ''High-performance IPC and RPC for microservices and apps''
Alexey Orlenko ''High-performance IPC and RPC for microservices and apps''Alexey Orlenko ''High-performance IPC and RPC for microservices and apps''
Alexey Orlenko ''High-performance IPC and RPC for microservices and apps''
 

More from John Tubert

Bunch of random tech things
Bunch of random tech thingsBunch of random tech things
Bunch of random tech things
John Tubert
 

More from John Tubert (8)

Sibling rivalry tech vs. philosophy on bias in ai
Sibling rivalry  tech vs. philosophy on bias in aiSibling rivalry  tech vs. philosophy on bias in ai
Sibling rivalry tech vs. philosophy on bias in ai
 
Sibling rivalry tech vs. philosophy on bias & AI
Sibling rivalry  tech vs. philosophy on bias & AISibling rivalry  tech vs. philosophy on bias & AI
Sibling rivalry tech vs. philosophy on bias & AI
 
Extreme Danger of bias in Artificial Inteligence
Extreme Danger of bias in Artificial InteligenceExtreme Danger of bias in Artificial Inteligence
Extreme Danger of bias in Artificial Inteligence
 
Sketchio presentation at Parse Developer meetup
Sketchio presentation at Parse Developer meetupSketchio presentation at Parse Developer meetup
Sketchio presentation at Parse Developer meetup
 
Browserless javascript testing
Browserless javascript testingBrowserless javascript testing
Browserless javascript testing
 
Drawing room experiment
Drawing room experimentDrawing room experiment
Drawing room experiment
 
Parse.com
Parse.comParse.com
Parse.com
 
Bunch of random tech things
Bunch of random tech thingsBunch of random tech things
Bunch of random tech things
 

Recently uploaded

EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
Earley Information Science
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 

Recently uploaded (20)

TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 

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 Leap’s 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)');