Hello,
For my artistic machine project, I need to sample a movement and play it on a loop. This sample must be set on the tempo!
But, there is a small problem, let me explain:
I draw a movement with the mouse for two seconds.
It is repeated in loop starting exactly on the beginning of a new second.
The problem is that the number of frames per second is not constant.
Sometimes it takes 27 frames/sec, sometimes 28.
So I see discrepancies. I would have to manage to play this loop exactly from its beginning every two seconds.
The defect on two seconds is minimal, but on 8 seconds I have more significant shifts.
We have to find a way to have the same data beginning each two seconds
I think I need to move back datas each two cycles of one positions in the table of datas recorded . I think the solution is something like that
if actualSec%2==0
mx[i]=mx[i-1]
my[i]=my[i-1]
Thank you for your contributions.
My program below. NB: To create movement it is enough to press once the mouse. The drawing will start to be saved
at the beginning of the two-second period and exactly when the second changes.
//int num = 40; // you need normally 45 frames/s but actually with a 3D setting you need only 40 frames
int num = 27; // you need normally 30 frames/s but actually with a 3D setting you need only 26.33 frames
int numberSec = 2;
float mx[] = new float[num*numberSec]; // position X memorised
float my[] = new float[num*numberSec]; //
float rx[] = new float[num*numberSec]; // position X recorded
float ry[] = new float[num*numberSec];
int beginTime,endTime,TimeMiddleElapsed,LastTimeMiddleElapsed,LastTimeElapsed;
int frame;
int restartTimer;
float Timer,Timer2;
boolean mouseRecorded;
boolean synchroMeasure;
boolean beginSampling, endSampling;
int lastLastSec,lastSec,actualSec;
public void settings() { //
size(600, 600, P3D);
}
void setup()
{
endSampling= false;
synchroMeasure= false;
mousePressed=false;
mouseRecorded=false;
frameRate (30);
noStroke();
fill(255, 0, 0, 50);
println("Start Drawing!");
}
void draw(){
if (lastLastSec!=lastSec){
print( " SAMPLING MODE " ) ; print( " LASTLASTSEC " ) ; print( lastLastSec ) ; print( " LASTLAST%2 " ); print( lastLastSec%2 );
print( " ACTUAL " ) ; print( actualSec ) ; print( " ACTUAL " ) ; print( actualSec ) ; print( " ACTUAL " ) ; println( actualSec ) ;
lastLastSec=lastSec;
synchroMeasure=true;
background(40, 40, 255);
}
else synchroMeasure=false;
if (actualSec!=lastSec){
lastSec=actualSec;
}
actualSec = second()%(numberSec+1); // Values from 0 - x number of secondes
samplingMovement(numberSec);
}
void samplingMovement(float timeSec) {
if (mousePressed==true)
{
mouseRecorded=true;
}
if(synchroMeasure==true && lastLastSec>=numberSec && lastLastSec<=numberSec){
beginSampling=false;
}
if (mouseRecorded==true && synchroMeasure==true && lastLastSec<=0//
) {
print (" Restart Record "); print (" Restart Record "); println (" Restart Record ");
mouseRecorded=false;
endSampling= false;
beginSampling=true;
frame = 0; //
}
frame=frame+1;
int i = int(frame%(num*timeSec+0)); // number of datas record = number of frame/ s multipled by secondes
if( beginSampling==true ) // frame>=0 &&
{
rx[i] = mouseX;
ry[i] = mouseY;
mx[i] = rx[i];
my[i] = ry[i];
fill(255, 0, 0, 50);
circle(rx[i], ry[i], 10);
if (frame%1<=0) {
print (" frame "); print (frame); print (" ry "); print (i); print (" "); println (ry[i]); //
}
}
if( endSampling==true ) // begin to replay for 2 sec . If I Add frame>num*timeSec+1, there is no effect
{
circle(mx[i]+400, my[i], 10);
if (frame%1<=0) {
print (" frame "); print (frame); print (" ry "); print (i); print (" "); println (ry[i]); //
}
}
if(synchroMeasure==true && lastLastSec>=timeSec && lastLastSec<=timeSec){ // important to put condition here! or on the of the main loop
endSampling=true;
}
}