Created
October 19, 2011 20:14
-
-
Save yoamomonstruos/1299529 to your computer and use it in GitHub Desktop.
CSM: Processing
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
/** | |
* Minor modifications (by Rebecca, Angus, Ben) to | |
* Shared Drawing Canvas (Client) | |
* by Alexander R. Galloway. | |
* | |
* The Processing Client class is instantiated by specifying a remote | |
* address and port number to which the socket connection should be made. | |
* Once the connection is made, the client may read (or write) data to the server. | |
* Before running this program, start the Shared Drawing Canvas (Server) program. | |
*/ | |
import processing.net.*; | |
Client c; | |
String input; | |
int data[]; | |
// Set your color here | |
int myR = 43; | |
int myG = 248; | |
int myB = 246; | |
int lastX = 0; | |
int lastY = 0; | |
void setup() | |
{ | |
size(1224, 968); | |
background(0, 0, 0); | |
stroke(0); | |
frameRate(5); // Slow it down a little | |
// Connect to the server's IP address and port | |
c = new Client(this, "0.0.0.0", 10000); // Replace with your server's IP and port | |
} | |
void draw() | |
{ | |
if (mousePressed == true) { | |
// Draw based on our local mouse input | |
stroke(myR,myG,myB); | |
line(pmouseX, pmouseY, mouseX, mouseY); | |
// Send mouse coords to other person (integers with space between set as string) | |
c.write(pmouseX + " " + pmouseY + " " + mouseX + " " + mouseY + " " + myR + " " + myG + " " + myB+"\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 | |
if (data.length==7) { | |
// Draw based on the data you get from the server. | |
int bR = int(random(0, 255)); | |
int bG = int(random(0, 255)); | |
int bB = int(random(0, 255)); | |
stroke(bR, bG, bB); | |
line(lastX, lastY, data[2], data[3]); | |
lastX = data[2]; | |
lastY = data[3]; | |
} else { | |
println("bad line of data"); | |
} | |
} | |
} | |
void keyPressed() { | |
background(0, 0, 0); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment