Network Library and the Draw() function
in
Core Library Questions
•
2 years ago
I recently adapted the 'Loop' sketch in the Processing examples to take a mouse position from another application across a network. The position of the video is now controlled by a remote mouse input. All this works fine with one exception that is the nice trails that follow the video around the screen do not occur in the networked version.
Here's a screen capture for the original 'Loop' sketch :
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Code for the Original Loop Sketch in Processing Examples folder //////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
import processing.video.*;
Movie myMovie;
void setup() {
size(640, 480, P2D);
background(0);
// Load and play the video in a loop
myMovie = new Movie(this, "station.mov");
myMovie.loop();
}
size(640, 480, P2D);
background(0);
// Load and play the video in a loop
myMovie = new Movie(this, "station.mov");
myMovie.loop();
}
void movieEvent(Movie myMovie) {
myMovie.read();
}
myMovie.read();
}
void draw() {
tint(255, 20);
image(myMovie, mouseX-myMovie.width/2, mouseY-myMovie.height/2);
}
tint(255, 20);
image(myMovie, mouseX-myMovie.width/2, mouseY-myMovie.height/2);
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
The networked version gets the mouse position (in this case just the X value) and passes it to Processing.
In this case however I lose the graphic trails from the original version illustrated above.
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// My adapted sketch with the mouse coordinates being passed in through /////
// an XML socket from AS3 /////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
import processing.net.*;
int port = 8080;
Server myServer;
import processing.net.*;
int port = 8080;
Server myServer;
Client thisClient;
int myX;
int myX;
import processing.video.*;
Movie myMovie;
Movie myMovie;
void setup()
{
size(640, 480, P2D);
background(0);
myServer = new Server(this, port);
myMovie = new Movie(this, "station.mov");
myMovie.loop();
}
void movieEvent(Movie myMovie) {
myMovie.read();
}
void draw()
{
thisClient = myServer.available(); // this line seems to remove the ttrailing effect
if (thisClient !=null) {
background(0);
String incomingMouseData = thisClient.readString();
{
thisClient = myServer.available(); // this line seems to remove the ttrailing effect
if (thisClient !=null) {
background(0);
String incomingMouseData = thisClient.readString();
//******************************************************************************
// the next two lines strip away what appears to be a stray linefeed that
// comes with the XML data from Flash
//*******************************************************************************
int theLength = incomingMouseData.length() -1;
int theLength = incomingMouseData.length() -1;
String mySubstring = incomingMouseData.substring(0,theLength);
myX = int(mySubstring);
myX = int(mySubstring);
if(myX != 0){
image(myMovie, myX, 100); // I don't get any trails from this line while the movie is translated by the remote cursor
}
}
}
image(myMovie, myX, 100); // I don't get any trails from this line while the movie is translated by the remote cursor
}
}
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
If anyone could shed some light on how I might maintain the trails in this situation I would be sincerely grateful.
Cheers
1