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 › creating a delay/timing for each picture
Page Index Toggle Pages: 1
creating a delay/timing for each picture (Read 1980 times)
creating a delay/timing for each picture
Jun 29th, 2009, 5:23pm
 
First off, sorry if I posted this is in the wrong place.

So here's the basicsof my project I'm working on:

I'm parsing in a .log file with three type of info (time, location, test) and so I'm trying to create a map with little icons flying to and from each location.

So far I can make one file go from one place to another and loop.  But when I try to do two icons moving, it starts at the same time so they overlap.  So my problem is that I want to give each icon its own timing so that they'd start a few milliseconds apart and thus won't overlap.  I can't seem to do that without changing the entire frameSpeed of the project though.

Here's my messy code that I've chugged out until I hit my roadblock; it may or may not help.

Code:
PImage mapLayer1, mapLayer2, mapLayer3, file1, file2;
String lines[];
String items[];
String time, loc, test;
boolean start = true;
boolean mapIn = false;
int frame, count1;
String test1, test2, test3;

void setup(){
 size(1000,527);
 lines = loadStrings("live.log");
 smooth();
 frameRate(10 );
 file1 = loadImage("file.png");
 file2 = loadImage("file2.png");


 for(int i = 0; i < lines.length; i++){
   String data = join(lines, " ");      //CONCAT THE 27 STRING ELEMENTS INTO ONE STRING
   items = split(data, " ");   //SPLIT THE STRING INTO ONE ARRAY
 }

 if(start == true){
   mapLayer1 = loadImage("scc1.png");
   background(mapLayer1);
   start = false;  
 }
}

void draw(){
 frame++;
 background(mapLayer1);

 if(count1 == 120){
   count1 = 0;
 }

 for(int z=2; z <= 83; z+=3){
   test = items[z];

   if(count1 <= 120){
     if(test.equals("cluster")){
       //ellipse(385-(count1*2.05), 255+(count1), 10,10);
       frameRate(10);
       image(file1, 382-(count1*2.1), 248+(count1));
       count1++;
     }
     else if(test.equals("grid")){
       image(file2, 382-(count1*2.1), 248+(count1));
       count1++;
     }
   }
 }
}
I hope that makes sense.  I would very much appreciate any and all help you can provide me with.  Thanks in advance.
Re: creating a delay/timing for each picture
Reply #1 - Jun 30th, 2009, 12:56am
 
Woah, you made a record: 6 times the same message! Wink
A glitch of the new forum...
Would you be so kind to go to each extra message and delete it please? Thanks.

To your program.
I am not too sure to understand what you are trying to do.
You need to have two icons racing from the same points, the rate of progression of each one depending on the content of a file?
Re: creating a delay/timing for each picture
Reply #2 - Jun 30th, 2009, 9:44am
 
Deleted!  It gave me a few errors when I tried to submit the first time, and I didn't know if it went through.

So essentially what I'm trying to do is get one icons constantly going from one point to the other.  It will look something like a pulse; one icons leaves and then midway through its path from A to B, another icon leaves from A, then midway through that path, another one leaves, etc.

Ideally the rate of these icons leaving point A will depend on the data in the file, but for now I'm just trying to make something work.
Re: creating a delay/timing for each picture
Reply #3 - Jun 30th, 2009, 1:02pm
 
Maybe the following code might inspire you:
Code:
String[] stuff = { "R", "B", "C", "C", "B", "B", "R", "C", "B", "R", "R", "C", "B" };
float[] pos = new float[stuff.length];
int start;
int runnerNb;
float step = 2.1;
float startPos = 82;

void setup()
{
size(100, 527);
smooth();
frameRate(10);
start = millis();
// pos[0] = startPos;
}

void draw()
{
background(200);
if (millis() - start > 1000)
{
pos[runnerNb++] = startPos;
start = millis();
}
for (int i = 0; i < runnerNb; i++)
{
DrawIcon(i);
pos[i] += step;
}
}

void DrawIcon(int id)
{
String shapeId = stuff[id];
if (shapeId.equals("B"))
{
fill(#0000FF);
}
else if (shapeId.equals("R"))
{
fill(#FF0000);
}
else if (shapeId.equals("C"))
{
fill(#00FFFF);
}
rect(50, pos[id], 20, 20);
}
Re: creating a delay/timing for each picture
Reply #4 - Jul 8th, 2009, 4:25pm
 
I totally forgot I asked this.  Thank you for that!  That was exactly the type of thing I was looking for.
Re: creating a delay/timing for each picture
Reply #5 - Jul 27th, 2009, 5:05pm
 
Hey again.  So what PhiLho provided me was extremely helpful (albeit a bit confusing to me) with movement in a straight line.  But now I'm trying to apply it to a curve and am having serious trouble with it.  I figured out the bezierPoint thing and can animate one picture just fine, just not the rest.

Any insight on how to make this work for a bezierCurve?  Please and thank you.
Re: creating a delay/timing for each picture
Reply #6 - Jul 28th, 2009, 2:12am
 
If your source isn't too big, you should post it (or a simplified version, so we can run it), so we can see what goes wrong.
Re: creating a delay/timing for each picture
Reply #7 - Jul 28th, 2009, 11:52am
 
Here's my code:

Code:
float count;
float px, py;
String[] stuff = { "R", "B", "C", "C", "B", "B", "R", "C", "B", "R", "R", "C", "B" };
float[] posx = new float[stuff.length];
float[] posy = new float[stuff.length];
int start;
int i;
float step = 2.1;
float startPosx = 350;
float startPosy = 10;

void setup(){
 size(400,400);
 smooth();
 frameRate(10);
 start = millis();
}

void draw(){
 background(255);
 stroke(0);
 bezier(350,10, 80,5,80,75, 10,350);

 count+=0.01;
 px = bezierPoint(350,80,80,10,count);
 py = bezierPoint(10,5,75,350,count);
 
 if(millis() - start > 100){
   posx[i++] = px;
   posy[i++] = py;
   if(i == stuff.length-1) i=0;
   start = millis();
 }
 for(int k = 0; k < i; k++){
  DrawIcon(k);
 }

 if(count >=1) count=0;
}

void DrawIcon(int id){
 String shapeId = stuff[id];
 if (shapeId.equals("B"))  {
   fill(#0000FF);
 }
 else if (shapeId.equals("R"))  {
   fill(#FF0000);
 }
 else if (shapeId.equals("C"))  {
   fill(#00FFFF);
 }
 ellipse(posx[id],posy[id], 10,10);
}


I tried making a simple one using the code you showed me.  I thought that if I put the x and y points on the curve into the array I could use those to draw an ellipse.  But it's not working out like that.  It's actually drawing two sets of ellipses, but I only used the ellipse method once.    Sad
Re: creating a delay/timing for each picture
Reply #8 - Jul 28th, 2009, 2:41pm
 
First remark: you increment i twice in posx/posy... If you fix that and add noFill() before the bezier() call, it is already greatly improved.
Code:
  if(millis() - start > 100){
posx[i] = px;
posy[i] = py;
if(++i == stuff.length-1) i=0;
start = millis();
}

But well, it can be better.
I add:
float[] counts = new float[stuff.length];
at the start.
And I rewrite draw():
Code:
void draw(){
background(255);
stroke(0);
noFill();
bezier(350, 10, 80, 5, 80, 75, 10, 350);

if(millis() - start > 1000) {
// Another one starting at the initial point
posx[i] = 350;
posy[i] = 10;
counts[i] = 0;
if (i < stuff.length - 1) i++;
start = millis();
}
for(int k = 0; k < i; k++) {
DrawIcon(k);

counts[k] += 0.01;
if (counts[k] >= 1) counts[k] = 0;
px = bezierPoint(350, 80, 80, 10, counts[k]);
py = bezierPoint(10, 5, 75, 350, counts[k]);
posx[k] = px;
posy[k] = py;
}
}
Page Index Toggle Pages: 1