-
Notifications
You must be signed in to change notification settings - Fork 74
/
LewittDrawing.pde
46 lines (42 loc) · 1 KB
/
LewittDrawing.pde
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
import java.net.*;
import java.util.Enumeration;
import processing.net.*;
Client c;
String serverIP = "127.0.0.1";
String input;
int[] data;
int myID;
void setup() {
size(800, 600);
frameRate(30);
c = new Client(this, serverIP, 12345);
myID = getIpLastNumber();
}
void draw() {
if (mouseX != pmouseX && mouseY != pmouseY) {
c.write(myID + " 0 " + mouseX + " " + mouseY + "\n");
}
}
void mousePressed() {
c.write(myID + " 1\n");
}
int getIpLastNumber() {
try {
Enumeration e = NetworkInterface.getNetworkInterfaces();
while (e.hasMoreElements()) {
NetworkInterface n = (NetworkInterface) e.nextElement();
Enumeration ee = n.getInetAddresses();
while (ee.hasMoreElements()) {
InetAddress i = (InetAddress) ee.nextElement();
String ip = i.getHostAddress();
if (ip.startsWith("192.")) {
return Integer.parseInt(ip.substring(1+ip.lastIndexOf(".")));
}
}
}
}
catch(Exception ex) {
ex.printStackTrace();
}
return 0;
}