Skip to content

Instantly share code, notes, and snippets.

@ralphtheninja
Last active August 29, 2015 14:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ralphtheninja/d118a675ec49b8f793ff to your computer and use it in GitHub Desktop.
Save ralphtheninja/d118a675ec49b8f793ff to your computer and use it in GitHub Desktop.
lasercat-workshop
var http = require('http')
var server = http.createServer()
var io = require('socket.io')(server)
board.on('ready', function () {
// ..
})
server.listen(9582)
<!doctype html>
<html>
<head>
<script src="http://localhost:9582/socket.io/socket.io.js"></script>
<title>LaserCat</title>
<style>
body {
margin: 0;
}
div#main {
position: absolute;
background: #ccc;
left: 0px;
top: 0px;
width: 100%;
height: 100%;
}
div#marker {
position: absolute;
background: #911;
left: 0px;
top: 0px;
width: 8px;
height: 8px;
border-radius: 50%;
margin: -4px 0 0 -4px;
}
</style>
</head>
<body>
<div id="main"></div>
<div id="marker"></div>
<script type="text/javascript">
var socket = io("http://localhost:9582");
var main = document.getElementById('main');
var marker = document.getElementById('marker');
document.addEventListener('mousemove', function (e) {
var x = e.clientX;
var y = e.clientY;
marker.style.left = x + 'px';
marker.style.top = y + 'px';
var xAngle = 0; // TODO
var yAngle = 0; // TODO
socket.emit('x', xAngle);
socket.emit('y', yAngle);
})
function pixelToAngle(n, fromLow, fromHigh, toLow, toHigh) {
return (n - fromLow) * (toHigh - toLow) / (fromHigh - fromLow) + toLow;
}
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment