Last active
August 29, 2015 14:16
-
-
Save ralphtheninja/d118a675ec49b8f793ff to your computer and use it in GitHub Desktop.
lasercat-workshop
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
var http = require('http') | |
var server = http.createServer() | |
var io = require('socket.io')(server) | |
board.on('ready', function () { | |
// .. | |
}) | |
server.listen(9582) |
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
<!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