I demonstrated how to mix sketches (kind of) in
http://bazaar.launchpad.net/~philho/+junk/Processing/files/head:/_SmallPrograms/DrawingInSequence/ but it is a bit advanced as example, and perhaps not addressing your need. But it also shows how to time the run of a sequence, and to chain such runs, just using millis().
Mmm, OK, here is a simpler sketch, perhaps closer of what you shown in a previous thread:
- int startTime;
- int step;
- int firstStepTime = 2000;
- int secondStepTime = 3000;
-
- float cx, cy;
- float count;
- color initialColor = #BBCC00;
- color circleColor = initialColor;
- int circleSize = 100;
- float circleStep = PI / 150;
-
- void setup()
- {
- size(512, 512);
- }
-
- void draw()
- {
- background(255);
- if (step == 0)
- {
- if (millis() - startTime >= firstStepTime)
- {
- // Change color every 2 seconds
- circleColor = circleColor == initialColor ? #DDEE00 : initialColor;
- startTime = millis();
- }
- }
- else if (step == 1)
- {
- if (millis() - startTime >= secondStepTime)
- {
- // Change color after 3 s
- circleColor = #DD5500;
- }
- }
- showCircle();
- }
-
- void showCircle()
- {
- cx = width / 2 + 200 * cos(count);
- cy = height / 2 + 200 * sin(count);
- count += circleStep;
- noStroke();
- fill(circleColor);
- ellipse(cx, cy, circleSize, circleSize);
- }
-
- void mouseClicked()
- {
- if (dist(mouseX, mouseY, cx, cy) < circleSize / 2)
- {
- step = 1;
- startTime = millis();
- circleStep = -circleStep;
- circleColor = #BB5500;
- }
- }
As you can see, one can change the behavior of the sketch (I could have put showCircle in step 0 and called another function in step 1) based on time and / or user interaction.
In Java / Processing, calling another program is a bit clumsy, it is easier / faster to modularize the program, and call the appropriate section when the need arises.