Hi everyone!

I’m trying to make a movement repeating himself by adapting the end with the beginning of the movement.

For example I try to draw a circle or the shape " 8 " during an elapsed time.

I would like to have one interpolation between the two last positions X and Y with the two first positions X and Y in order to not have a big space between last and first positions.

In my program, try to make the shape " 8 " in a period of 2 sec, the drawing will be record between measure 2 and 4 and automatically after the draw will repeat it self

Thanks for your help.

```
int actualSec,lastSec,measure;
boolean bRecording = false;
boolean mouseRecorded = true;
class Sample {
int t, x, y;
Sample( int t, int x, int y ) {
this.t = t; this.x = x; this.y = y;
}
}
class Sampler {
ArrayList<Sample> samples;
int startTime;
int playbackFrame;
Sampler() {
samples = new ArrayList<Sample>();
startTime = 0;
}
void beginRecording() {
samples = new ArrayList<Sample>();
playbackFrame = 0;
}
void addSample( int x, int y ) {
int now = millis();
if( samples.size() == 0 ) startTime = now;
samples.add( new Sample( now - startTime, x, y ) );
}
int fullTime() {
return ( samples.size() > 1 ) ?
samples.get( samples.size()-1 ).t : 0;
}
void beginPlaying() {
startTime = millis();
playbackFrame = 0;
println( samples.size(), "samples over", fullTime(), "milliseconds" );
}
void draw() {
stroke( 255 );
beginShape(LINES);
for( int i=1; i<samples.size(); i++) {
vertex( samples.get(i-1).x, samples.get(i-1).y );
vertex( samples.get(i).x, samples.get(i).y );
}
endShape();
int now = (millis() - startTime) % fullTime();
if( now < samples.get( playbackFrame ).t ) playbackFrame = 0;
while( samples.get( playbackFrame+1).t < now )
playbackFrame = (playbackFrame+1) % (samples.size()-1);
Sample s0 = samples.get( playbackFrame );
Sample s1 = samples.get( playbackFrame+1 );
float t0 = s0.t;
float t1 = s1.t;
float dt = (now - t0) / (t1 - t0);
float x = lerp( s0.x, s1.x, dt );
float y = lerp( s0.y, s1.y, dt );
circle( x, y, 10 );
}
}
Sampler sampler;
void setup() {
size( 800, 800, P3D );
frameRate( 30 );
sampler = new Sampler();
}
void draw() {
activeSampling();
stopSampling();
if (actualSec!=lastSec){
lastSec=actualSec;
measure++;
}
actualSec =(int) (millis()*0.001); //
background( 0 );
if( bRecording ) {
circle( mouseX, mouseY, 10 );
sampler.addSample( mouseX, mouseY );
} else {
if( sampler.fullTime() > 0 )
sampler.draw();
}
}
void mousePressed() {
mouseRecorded = true;
}
void activeSampling() {
if (measure<=2 && measure>=2 &&actualSec!=lastSec && mouseRecorded == true) {
bRecording = true;
sampler.beginRecording();
}
}
void stopSampling() {
if (measure<=4 && measure>=4 && actualSec!=lastSec) {
mouseRecorded = false;
bRecording = false;
sampler.beginPlaying();
}
}
```