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.
IndexProcessing DevelopmentLibraries,  Tool Development › Loading Sketches as if they were libraries/plugins
Page Index Toggle Pages: 1
Loading Sketches as if they were libraries/plugins (Read 800 times)
Loading Sketches as if they were libraries/plugins
Nov 2nd, 2007, 5:29pm
 
Hi all!

I am currently looking into the processing source code and documentation, to see to what extent it would be possible to have a main sketch, and then dynamically load .jar files containing existing sketches, for these to be used as plug-in libraries.

Of course this would require many constraints (main and plug-in sketches all being in one mode such as OpenGL, all having been exported using the same version of processing, etc), but the benefits of it would be so great that I’m sure it would be worth the effort!

This is with the goal of developing a library, for me to use and of course to release in to the Processing community as open source. I have many years of programming experience using C++ and C#, but I’m new to java, have been learning it since just 3 weeks for this project, so I am not very familiar with its libraries/particularities yet.

Starting much more modestly for now, I have made an example pasted at the end of this post, as it appears in eclipse.

The problem is that to get closer to the goal, I need to do away with the “parent.” reference in the plug-in sketches “LightRedGL” and “LightBlueGL”. If I just delete it of course it all just crashes when I try to run it, but I am hoping that somehow it may be possible to simply update the references in the sketches that are loaded as plugins, and thus make this possible.

Do you have any suggestions as to how this may be done?

If I add the lines

sven.g
= this.g;
hilda.g
= this.g;
sven.width
= this.width;
hilda.width  = this.width;
sven.height  = this.height;
hilda.height = this.height;

in the main (Mother) class setup(), it doesn’t crash when I’ve removed the parent reference any more, but I am sure a lot of functionality would need fixing still, that I just haven’t tried using.

Anyhow, sorry for the slightly lengthy post, I am looking forward to what suggestions you may have so that I can get this library out as soon as possible!

Regards, Ilias B.

A sketch class that is intended to load and initiate drawing from the plug-in sketches:
---------------------------------------
import processing.core.*;

public class Mother extends PApplet
{

LightRedGL sven;

LightBlueGL hilda;


static public void main(String args[])

{    


PApplet.main(new String[] { "Mother" });

}


public void setup()

{

 size(640, 480, OPENGL);

 

 sven = new LightRedGL(this);

 hilda = new LightBlueGL(this);

}


public void draw()

{


background(0);


sven.draw();


hilda.draw();

}
}
---------------------------------------

…and two sketches:
---------------------------------------

import processing.core.*;

public class LightRedGL extends PApplet
{

PApplet parent;


public LightRedGL(PApplet p_in)
{ parent = p_in;
}


public void setup()

{


parent.size(400, 300, OPENGL);

}


public void draw()

{

parent.pushMatrix();

parent.fill(255,0,0);

parent.translate(0.25f*parent.width, 0.25f*parent.height);

parent.rotateY(parent.map(parent.mouseX,0,parent.width,0,PI));


parent.rotateX(parent.map(parent.mouseY,0,parent.height,0,PI));

parent.box(90);

parent.popMatrix();

}
}

---------------------------------------

import processing.core.*;

public class LightBlueGL extends PApplet
{

PApplet parent;


public LightBlueGL(PApplet p_in)
{ parent = p_in;
}


public void setup()

{


parent.size(400, 300, OPENGL);

}


public void draw()

{

parent.pushMatrix();

parent.fill(0,0,255);

parent.translate(0.75f*parent.width, 0.75f*parent.height);

parent.rotateY(parent.map(parent.mouseX,0,parent.width,0,PI));

parent.rotateX(parent.map(parent.mouseY,0,parent.height,0,PI));

parent.box(90);

parent.popMatrix();

}
}

---------------------------------------
Re: Loading Sketches as if they were libraries/plu
Reply #1 - Nov 3rd, 2007, 4:59pm
 
there are a couple other threads on the board about making a parent class that runs several other processing applets. give 'em a look for some initial guidance on how to do things, and then follow up once you have some general ideas on how to do it.
Page Index Toggle Pages: 1