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 › Load sketches based on presentation time
Page Index Toggle Pages: 1
Load sketches based on presentation time (Read 312 times)
Load sketches based on presentation time
Dec 17th, 2008, 6:31pm
 
Hello!
I'm quite new to processing, previously played with quartz composer. I stumbled  upon a problem that qc struggles to work with multiple webcams instantly. Therefore tried to code my concept into processing and with success!; seems I won't even go back :)

The question:
I have multiple (in the endproject presumably 5) sketches. The representation could be:

// sketch 1
void setup()
{

// hundreds of lines

size(200,200);

frameRate(30);
}
void draw()
{

// hundreds of lines

background(255,0,0);
}

// sketch 2
void setup()
{

size(200,200);

frameRate(30);
}
void draw()
{

background(0,100,0);
}

// sketch 3
void setup()
{

size(200,200);

frameRate(30);
}
void draw()
{

background(0,0,255);
}

Basically n totaly independent compositions, each displaying different things (not just changing bg colour :)), each one using different libraries etc.

Is processing able to load sketches dynamically based on some rule? What I need is for the compositions to change every n minutes and/or when speciffic data has changed in mysql. Of course, I could merge all the code in one file, but then it will become messy. I'd simply like to keep every sketch independent, so they would be more easily to manage etc etc.

The pseudoscript could be

// a "mastersketch" to load and display other sketches
global - define paths to sketches, maybe set up some rules for each

void setup()
{
//setup
}

void draw()
{
//Loading and drawing other sketches, based on some rules, whatever they are (time, iteration position, rule that's read from mysql etc).

//based on time, a fast implementation ;) loads 3 sketches, each one shown for 20 seconds
 if (second() >= 0 && second() < 20) {
   loadsketch[1];
 }
 else if (second() >= 20 && second() < 40) {
   loadsketch[2];
 }
 else {
   loadsketch[3];
 }
}

Maybe there's other way to achieve this?

Many thanks in advance,
kroko
Re: Load sketches based on presentation time
Reply #1 - Dec 21st, 2008, 6:11am
 
Well, the quickest path is to export to application and call them from a script, like python.  The problem with using Processing to do this is because it is an applet, so you will definitely have problem executing resources outside of a sketch.

Other way is to have the drawing routine be modified into a class and call them as you see fit.  You can make it into a package, but that is more like a Java application rather than a sketch.


Former one looks like the solution for you, since you just want to use an existing sketch with minimum modification.  What do you think?
Page Index Toggle Pages: 1