# Delay an event by 200ms. Why can I shift one and not several?

**URL:** https://discourse.processing.org/t/delay-an-event-by-200ms-why-can-i-shift-one-and-not-several/35777
**Category:** Coding Questions
**Created:** [March 16, 2022, 12:04pm UTC](https://discourse.processing.org/t/delay-an-event-by-200ms-why-can-i-shift-one-and-not-several/35777 "2022-03-16T12:04:45Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![bking](https://avatars.discourse-cdn.com/v4/letter/b/dc4da7/32.png) [@bking](https://discourse.processing.org/u/bking)
#### Post date: [March 16, 2022, 12:04pm UTC](https://discourse.processing.org/t/delay-an-event-by-200ms-why-can-i-shift-one-and-not-several/35777/1 "2022-03-16T12:04:45Z")

</div>

Good morning all!

For my artistic installation, I would like from the movement of a point rotating at constant speed, to be able to make 9 other points follow the first with temporal and spatial shifts.  
Here is the link to see examples of uses with different temporal and spatial offsets.  
[https://youtu.be/IJ1tZstcywA](https://youtu.be/IJ1tZstcywA)  
In the video, I start changing the time to milliseconds and the shift phase. But the problem is that all the following points shift instantly, without waiting for 2XX milliseconds. :help:

To start, we must be able to make a point called 3 moving in a circular way, followed by another point called 2 also moving in a circular way. Point 2 at a constant circular speed  
Basically point 3 has no speed and is at position 0

I manage to manage a phase shift between 3 and 2 in two ways.  
a temporal:

So that 3 has phase 2 with zero or 200 ms lag time for example.  
In the first case, 3 and 2 have exactly the same position  
In the second we observe a latency.

a space:

In such a way that 3 has phase 2 with an offset position, i.e. if there is a gap between position 2 in motion and position 3 at rest, position 3 advances by - strokes, as soon as the difference between position 3 and 2 is greater than 45° for example.

Then try to see if we can combine the two:

Make position 3 move forward 45° after 200 ms from when the difference between position 2 and 3 was greater than 45°.

It is on this last part that I have a problem, I manage to do it with position 3 and 2, but I cannot generalize with the following positions. The 4 should follow the 3 with a delay of 200 ms and a gap of 45° and so on for the positions i+1 and i.  
Hoping to have been clear, I put the function below, if you have any ideas.  
I guess my problem is the way I trig my timers called formerEvent[j+1]  
Thank you for your efforts! 😉  
I give only the fonction for now it could enough to find the problem

```auto
 if (circularMov==true ){
    if (d>=0){
      decay=d; // decay in millis (50,.. 1000 ms), before changing phase i+1 with the phase from i
}   
   if (k>=0){
      phiShift=k*-PI/16; // here the position to add or substrat to the next point (i+1)
      mapShiftCircular= map (phiShift, 0, 16*-PI/16, 0, 6400); // one revolution is 6400 step 
  // mapShiftCircular is the space to reach in order to follow the previous point 
}
   formerEvent[2]=millis(); // time from the beginning of the launch of the program.
}

  for (int i = 2; i < (3); i++) { // BETWEEN point 3 and 2, program works!
      
       if ( circularMov==true && // mapShiftCircular is the space between two points
    //points goes in clock wise
    ((CircularOldVirtualPosition[2] <= CircularVirtualPosition[2+1]+mapShiftCircular) && (CircularVirtualPosition[2] >= CircularVirtualPosition[2+1]+mapShiftCircular) &&
     (CircularOldVirtualPosition[2]+800*0.1 < CircularVirtualPosition[2]+800*0.1))
   
    ||
    ((CircularOldVirtualPosition[2]+mapShiftCircular >= CircularVirtualPosition[2+1]) && (CircularVirtualPosition[2]<= CircularVirtualPosition[2+1]+mapShiftCircular) &&
     (CircularOldVirtualPosition[2]+800*0.1 > CircularVirtualPosition[2]+800*0.1))
    //points goes in counter clock wise
    )
  
     {  
          followNumber[i]= true;
     }
     else followNumber[i]= false; 
     
     if (
     formerEvent[2]>formerEvent[i+1]+decay && followNumber[i]== true // followNumber[i]== Is the test true work as it should? Maybe

       ){
    
         net.phase[3]=(net.phase[2])-phiShift*1;// net.oldPhase[i] keep phase at 0
         net.phase[3]= net.phase[3]%TWO_PI;// keep phase between 0 and TWO_PI
             
         memoryi=i; // to see which point to follow
         formerEvent[i+1]=formerEvent[2]; // former time where point i+1 was 
         print (" memoryiCircular= "); print (memoryi);
          }      
   }
 
 for (int j = 3; j < (11); j++) {
      
       if ( circularMov==true && //( // circularMov==true
   
    ((CircularOldVirtualPosition[j] <= CircularVirtualPosition[j+1]+mapShiftCircular) && (CircularVirtualPosition[j] >= CircularVirtualPosition[j+1]+mapShiftCircular) &&
     (CircularOldVirtualPosition[j]+800*0.1 < CircularVirtualPosition[j]+800*0.1))
   
    ||
    
    ((CircularOldVirtualPosition[j]+mapShiftCircular >= CircularVirtualPosition[j+1]) && (CircularVirtualPosition[j]<= CircularVirtualPosition[j+1]+mapShiftCircular) &&
     (CircularOldVirtualPosition[j]+800*0.1 > CircularVirtualPosition[j]+800*0.1))
  
    )
  
     { 
         followNumber[j]= true;
      // formerEvent[j+0]=formerEvent[2];
  }
     else followNumber[j]= false;
     
   if (
       formerEvent[2]>formerEvent[j+1]+decay && followNumber[j]==false //followNumber[i]== true doesn't work as it should
 // formerEvent[j+1]>formerEvent[j+2]+decay && followNumber[j]==true
   ){
    // background (127, 50,50);
       
          net.phase[j]=net.phase[j]%TWO_PI;
          net.phase[j+1]=(net.phase[j])-phiShift;// 
          net.phase[j+1]= net.phase[j+1]%TWO_PI;// keep phase between 0 and TWO_PI
       memoryi=j;  
       formerEvent[j+1]=formerEvent[2];  
       print (" memoryiCircular= "); print (memoryi);
       print (" followNumber "); print (followNumber[j]);
          }      
   }

```
