more example moving

This commit is contained in:
benfry
2012-04-08 15:59:40 +00:00
parent 1b81affbf0
commit 3b9ebc19f2
52 changed files with 0 additions and 0 deletions
@@ -0,0 +1,33 @@
import processing.net.*;
Client c;
String input;
int data[];
void setup() {
size(450, 255);
background(204);
stroke(0);
frameRate(5); // Slow it down a little
// Connect to the servers IP address and port
c = new Client(this, "127.0.0.1", 12345); // Replace with your servers IP and port
}
void draw() {
if (mousePressed == true) {
// Draw our line
stroke(255);
line(pmouseX, pmouseY, mouseX, mouseY);
// Send mouse coords to other person
c.write(pmouseX + " " + pmouseY + " " + mouseX + " " + mouseY + "\n");
}
// Receive data from server
if (c.available() > 0) {
input = c.readString();
input = input.substring(0, input.indexOf("\n")); // Only up to the newline
data = int(split(input, ' ')); // Split values into an array
// Draw line using received coords
stroke(0);
line(data[0], data[1], data[2], data[3]);
}
}