-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsketch.js
52 lines (44 loc) · 1.1 KB
/
sketch.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// Keep track of our socket connection
var socket;
function setup() {
createCanvas(windowWidth, windowHeight);
background(0);
// Start a socket connection to the server
// Some day we would run this server somewhere else
socket = io.connect('brewcontroller-cohbra.c9users.io');
// We make a named event called 'mouse' and write an
// anonymous callback function
socket.on('mouse',
// When we receive data
function(data) {
console.log("Got: " + data.x + " " + data.y);
// Draw a blue circle
fill(0,0,255);
noStroke();
ellipse(data.x,data.y,80,80);
}
);
}
function draw() {
// Nothing
}
function mouseDragged() {
// Draw some white circles
fill(255);
noStroke();
ellipse(mouseX,mouseY,80,80);
// Send the mouse coordinates
sendmouse(mouseX,mouseY);
}
// Function for sending to the socket
function sendmouse(xpos, ypos) {
// We are sending!
console.log("sendmouse: " + xpos + " " + ypos);
// Make a little object with and y
var data = {
x: xpos,
y: ypos
};
// Send that object to the socket
socket.emit('mouse',data);
}