Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
hagino3000
committed
Feb 22, 2011
1 parent
80bb280
commit c763aa1
Showing
6 changed files
with
2,631 additions
and
0 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
var ws = new WSMessage({ | ||
url : 'ws://localhost:8080', | ||
autoRecovery : true, | ||
listeners : { | ||
open : function(){console.info('onopen!!')}, | ||
close : function(){console.info('onclose!!')}, | ||
move : onMove, | ||
unregister : onUnKinectRegister, | ||
register : onKinectRegister, | ||
} | ||
}); | ||
|
||
var pointer = { | ||
locX : 0, | ||
locY : 0, | ||
size : 10, | ||
capture : true, | ||
captureTime : 0, | ||
visible : true | ||
} | ||
|
||
|
||
function onMove(data) { | ||
pointer.locX = Math.floor(data.x/100*WIDTH); | ||
pointer.locY = Math.floor(data.y/100*HEIGHT); | ||
//pointer.size = data.z; | ||
pointer.size = 80; | ||
} | ||
|
||
function onHandClick() { | ||
pointer.capture = true; | ||
pointer.captureTime = 5; | ||
} | ||
|
||
function onUnKinectRegister() { | ||
pointer.visible = false; | ||
} | ||
|
||
function onKinectRegister() { | ||
pointer.visible = true; | ||
} | ||
|
||
var WIDTH; | ||
var HEIGHT; | ||
|
||
function canvasStart() { | ||
HEIGHT = $(window).height(); | ||
WIDTH = $(window).width(); | ||
console.info('start canvas'); | ||
var canvas = document.getElementById('canvas1'); | ||
|
||
$(canvas).attr({ | ||
width : WIDTH, | ||
height : HEIGHT | ||
}); | ||
if ((ctx = canvas.getContext && canvas.getContext('2d'))) { | ||
pointer = { | ||
visible : true, | ||
locX : 0, | ||
locY : 0, | ||
size : 10 | ||
} | ||
setInterval(draw, 30); | ||
return; | ||
} | ||
alert('Error!! cannot get 2d context'); | ||
} | ||
|
||
var ctx; | ||
function draw() { | ||
|
||
ctx.globalCompositeOperation = "source-over"; | ||
ctx.fillStyle = "rgba(8,8,12,0.1)"; | ||
ctx.fillRect(0, 0, WIDTH, HEIGHT); | ||
//ctx.clearRect(0, 0, cInfo.WIDTH, cInfo.HEIGHT); | ||
ctx.globalCompositeOperation = "lighter"; | ||
|
||
if (pointer.visible) { | ||
ctx.beginPath(); | ||
if (pointer.captureTime > 0) { | ||
ctx.fillStyle = 'rgba(640,20,64, 0.8)'; | ||
pointer.captureTime -= 1; | ||
} else { | ||
ctx.fillStyle = 'rgba(20,20,64, 0.8)'; | ||
} | ||
ctx.arc(pointer.locX, pointer.locY, pointer.size, 0, Math.PI*2.0, true); | ||
ctx.fill(); | ||
} | ||
|
||
} | ||
|
||
$(canvasStart); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
var http = require('http'), | ||
io = require('socket.io'), | ||
zmq = require('zeromq'), | ||
json = JSON.stringify; | ||
|
||
|
||
var server = http.createServer(); | ||
server.listen(8080); | ||
|
||
var webSocket = io.listen(server); | ||
webSocket.on('connection', function(client) { | ||
console.info('browser connect!!!'); | ||
client.on('disconnect', function() { | ||
console.info('disconnect'); | ||
}); | ||
}); | ||
|
||
var zsocket = zmq.createSocket('sub'); | ||
zsocket.on('message', function(event, data) { | ||
console.info(data.toString()); | ||
webSocket.broadcast(data); | ||
}); | ||
zsocket.on('error', function(err) { | ||
console.info('error'); | ||
console.info(err.toString('utf8')); | ||
}); | ||
zsocket.connect('tcp://127.0.0.1:14444'); | ||
zsocket.subscribe('event'); | ||
|
||
|
Oops, something went wrong.