We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › communication between processing sketches
Page Index Toggle Pages: 1
communication between processing sketches? (Read 896 times)
communication between processing sketches?
Jan 14th, 2010, 3:11pm
 

I want to make multiple threads for my program.
Is it possible to have parallel threads inside a processing sketch?

If not, is it possible to make communicate two processing sketches that run at the same time?

I need help!
Thank you!
Re: communication between processing sketches?
Reply #1 - Jan 14th, 2010, 3:14pm
 
http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Runnable.html
Re: communication between processing sketches?
Reply #2 - Jan 15th, 2010, 2:36am
 
Hi,

dont know if it helps, but you can also create multiple PApplets in one sketch and abuse processings setting of all variables being global to communticate inbetween the single windows.
this code below is very quick and dirty, but it's just to give an simple example:

Code:
UIWindow uiWindow;
boolean draw_circles= false;

void setup() {
size(500, 200);
background(102);
smooth();
frame.setTitle("output window");

//init second window
uiWindow = new UIWindow( 500,240 );
frameRate(25);
}

void draw() {
frame.setLocation(screen.width-455,100); //just finxing the location of the frame
}

//some stuff from the 'examples' we want to do
void variableEllipse(int x, int y, int px, int py) {
float speed = abs(x-px) + abs(y-py);
stroke(speed);
ellipse(x, y, speed, speed); //quick and dirty, but as we call ellipse() here it is drawn to the default(first) window
}

//second window like e.g. Edvin_Besic postet
public class UIWindow extends PApplet {
Frame frame;
int width;
int height;
int col = 0;

UIWindow (int w, int h)
{
width = w;
height = h;

frame = new Frame();
frame.setBounds(0, 0, width, height);
frame.setLocation(screen.width-455,350);

frame.add(this);
this.init();
frame.show();
frameRate(25);
}

void setup( )
{
size(width,height);
frame.setTitle("input window");
noStroke();
}

void draw ( ){
variableEllipse(mouseX, mouseY, pmouseX, pmouseY); //call variableEllipse() that draws to the first window

//but we can also do some stuff here
fill(col,20,0);
rect(0,0,460,col);
col++;
if(col>=255) col = 0;
}
}


when doing things like this you only have to put an eye on not getting confused by too many globals.

cheers
Re: communication between processing sketches?
Reply #3 - Jan 15th, 2010, 4:58am
 
To answer the second question, Network is probably where you must look.
Re: communication between processing sketches?
Reply #4 - Jan 20th, 2010, 6:36am
 
Thanks, the Thread Class + Runnable is parfait.
Page Index Toggle Pages: 1