Bonjour,
Une balle [0] oscillant entre 0 et PI est suivie par 9 autres balles sans décalages temporels. Elles ont donc le meme signal.
J'aimerais, en appuyant une fois sur la flèche droite, que les balles de 1 à 9 autres suivent la balle 0 avec 1 à 9 * 500 ms seconde de retard.
J'ai un premier programme qui fonctionne, les balles suivent bien le signal avec 10, 20 ... frame de retard.
Mais je veux qu'elles suivent le signal en fonction de l'incrementation d'un temps et non par l'incrementation par image ( par la fonction frameCount qui s'actualise dans la main loop).
Comment puis je faire?
J'ai fait une variable qui s'actualise avec la fonction millis() qui s'actualise bien avec l'horloge du processeurs et non par frameCount.
Ca fonctionne, mais mon incrementation temporelle n'est pas precise.
Aussi, je n'arrive pas à récupérer les positions des balles qui suivent la balle 0.
Merci pour vos signaux éclairés!
PS: Ici est le programme où frameCount est remplacé par frameCountBis qui s'actualise avec millis()
String debug ="";
String dataToControlMotor;
boolean way;
// MANAGE PERSPECTIVE
import peasy.*;
// change these for screen size
float w = 1000;
float h = 800;
// don't change these
float w2 = w / 2;
float h2 = h / 2;
int nbBall = 9;
int nbMaxDelais = 2000;
float pendulairePhase;
float formerDecayTime, decayTime;
int frameCountBis = 0;
int lastSec, sec, countSec;
// Code pour option de follow
boolean firstFollowingLast = true;
float deltaFollow = PI/180;
boolean firstFollowingStarted = false;
float [][] phases = new float[nbBall][nbMaxDelais];
int[] phaseToMotor;
float [] phaseMapped;
float x, y;
float Phase;
int d, k; // to modulate parameter of phase and time offset
int frameRatio;
public void settings() {
size(600, 600, P3D);
}
void setup() {
new PeasyCam(this, 2000);
frameRatio=30;
countSec=0;
k=1;
frameRate(frameRatio);
for (int i = 0; i < nbBall; i++) {
phaseToMotor= new int [nbBall];
phaseMapped= new float [nbBall];
for (int j = 0; j < nbMaxDelais; j++)
phases[i][j] = PI;
}
}
void draw() {
background(0);
if (lastSec>=sec){
background (100);
countSec++;
};
if (formerDecayTime>=decayTime){
frameCountBis=frameCountBis+1;
}
formerDecayTime = decayTime;
decayTime = (millis()*1)%20;// counter actualise 20 times in on sec
lastSec= sec;
sec=millis()%1000;
println(frameCount + ": " + frameRatio + " : incrementTime " + frameCountBis + " Sec " + second() + " : sec " + countSec + " decayT " + decayTime + " : decay en ms " + d*50) ;
rotate(- TWO_PI ); //TO change the beginning of the 0 (cercle trigo) and the cohesion point to - HALF_PI
translate(width/2, -height/2, -1000);// To set the center of the perspective
if (!firstFollowingStarted) {
float signal = diffAngle(PI + (frameCountBis /4) * cos (1000 / 250.0), 0);
print ("signal ");
print ( signal );
float deltaFollow = PI/180;
if (signal > 0 )
phases[0][frameCountBis/1 % nbMaxDelais]= diffAngle(signal, HALF_PI);//%
else
phases[0][frameCountBis/1 % nbMaxDelais]= diffAngle(2* PI, signal + HALF_PI);//% TWO_PI
drawBall(0, phases[0][frameCountBis % nbMaxDelais]); // affiche le point 0. NE PAS AFFICHER SINON IL APPARAIT EN DOUBLE
}
for (int i = 1; i < nbBall; i++) {
debug ="Normal follow ";
// follow( i-1, i, 20 * i, 0); // Modifier les deux derniers paramètres : délais et phase
follow( i-1, i, d, k*QUARTER_PI/8); // ici, le temps que les points attendent pour se suivre est de d frames, et il faut un espace entre eux de QUARTER_PI/8
//***** drawBall(i, phaseMapped[i] );
drawBall(i, phases[i][frameCountBis*1 % nbMaxDelais] );
}
float balle0;
float balle1;
float balle2;
balle0 = phases[0][frameCountBis % nbMaxDelais];
balle1 = phases[1][frameCountBis % nbMaxDelais];
balle2 = phases[2][frameCountBis % nbMaxDelais];
println(" balle0 " + balle0 + " balle1 " + balle1 + " balle2 " + balle2) ;
}
void drawBall(int n, float phase) {
pushMatrix();
translate(-w2, -h2, -1000);
noStroke();
float side = height*0.15*1/nbBall;
float rayon = width/2;
x = rayon*cos(phase); //-300 à 300
y = rayon*sin(phase);
translate (x, y, 200+(50*5*n)); //
translate (100, 100, 200+(50*5*n));
colorMode(RGB, 255, 255, 255);
fill( 0, 255, 0 );
sphere(side*3);
popMatrix();
}
void follow( int target, int follower, int delais, float deltaphase) {
int step = frameCountBis % nbMaxDelais;
int followedStep = (step + nbMaxDelais - delais) % nbMaxDelais;
phases[follower][step] = diffAngle(phases[target][followedStep] + deltaphase, 0);
}
float diffAngle(float angle1, float angle2) { // return the difference angle1 - angle2 between two angle between -PI PI
float result = angle1 - angle2;
while (result > PI) {
result -= 2 * PI;
}
while (result < -PI) {
result += 2 * PI;
}
return result;
}
void keyPressed () {
if (keyCode == UP) {
frameRatio=frameRatio+5;
frameRatio=frameRatio%65;
if (frameRatio <=0 ){
frameRatio=5;
}
frameRate(frameRatio);
}
if (keyCode == DOWN) {
if (frameRatio <=5 ){
frameRatio=5;
}
frameRatio=frameRatio-1;
}
frameRate(frameRatio); // pas dans le void draw
if (keyCode == RIGHT) {
println(" right INCREASE timeOffset ") ; //
d+= 10; // incremente de demi sec. I need to increment 1282 to have 60 sec. So one sec is 1282/60 => 21.5 incrementations/sec
d=d%65;
print ("d= timeOffsetRatio: ");
println (d);
}
if (keyCode == LEFT) {
println(" left INCREASE phase shifting"); //
d-=10; // incremente de demi sec
}
}
programme avec FrameCount
String debug ="";
String dataToControlMotor;
boolean way;
// MANAGE PERSPECTIVE
import peasy.*;
// change these for screen size
float w = 1000;
float h = 800;
// don't change these
float w2 = w / 2;
float h2 = h / 2;
int nbBall = 9;
int nbMaxDelais = 2000;
float pendulairePhase;
float formerDecayTime, decayTime;
int frameCountBis = 0;
int lastSec, sec, countSec;
// Code pour option de follow
boolean firstFollowingLast = true;
float deltaFollow = PI/180;
boolean firstFollowingStarted = false;
float [][] phases = new float[nbBall][nbMaxDelais];
int[] phaseToMotor;
float [] phaseMapped;
float x, y;
float Phase;
int d, k; // to modulate parameter of phase and time offset
int frameRatio;
public void settings() {
size(600, 600, P3D);
}
void setup() {
new PeasyCam(this, 2000);
frameRatio=30;
countSec=0;
k=1;
frameRate(frameRatio);
for (int i = 0; i < nbBall; i++) {
phaseToMotor= new int [nbBall];
phaseMapped= new float [nbBall];
for (int j = 0; j < nbMaxDelais; j++)
phases[i][j] = PI;
}
}
void draw() {
background(0);
if (lastSec>=sec){
background (100);
countSec++;
};
if (formerDecayTime>=decayTime){
frameCountBis=frameCountBis+1;
}
formerDecayTime = decayTime;
decayTime = (millis()*1)%20;// counter actualise 20 times in on sec
lastSec= sec;
sec=millis()%1000;
println(frameCount + ": " + frameRatio + " : incrementTime " + frameCountBis + " Sec " + second() + " : sec " + countSec + " decayT " + decayTime + " : decay en ms " + d*50) ;
rotate(- TWO_PI ); //TO change the beginning of the 0 (cercle trigo) and the cohesion point to - HALF_PI
translate(width/2, -height/2, -1000);// To set the center of the perspective
if (!firstFollowingStarted) {
float signal = diffAngle(PI + (frameCount /4) * cos (1000 / 250.0), 0);
print ("signal ");
print ( signal );
float deltaFollow = PI/180;
if (signal > 0 )
phases[0][frameCount/1 % nbMaxDelais]= diffAngle(signal, HALF_PI);//%
else
phases[0][frameCount/1 % nbMaxDelais]= diffAngle(2* PI, signal + HALF_PI);//% TWO_PI
drawBall(0, phases[0][frameCount % nbMaxDelais]); // affiche le point 0. NE PAS AFFICHER SINON IL APPARAIT EN DOUBLE
}
for (int i = 1; i < nbBall; i++) {
debug ="Normal follow ";
// follow( i-1, i, 20 * i, 0); // Modifier les deux derniers paramètres : délais et phase
follow( i-1, i, d, k*QUARTER_PI/8); // ici, le temps que les points attendent pour se suivre est de d frames, et il faut un espace entre eux de QUARTER_PI/8
//***** drawBall(i, phaseMapped[i] );
drawBall(i, phases[i][frameCount*1 % nbMaxDelais] );
}
float balle0;
float balle1;
float balle2;
balle0 = phases[0][frameCount % nbMaxDelais];
balle1 = phases[1][frameCount % nbMaxDelais];
balle2 = phases[2][frameCount % nbMaxDelais];
println(" balle0 " + balle0 + " balle1 " + balle1 + " balle2 " + balle2) ;
}
void drawBall(int n, float phase) {
pushMatrix();
translate(-w2, -h2, -1000);
noStroke();
float side = height*0.15*1/nbBall;
float rayon = width/2;
x = rayon*cos(phase); //-300 à 300
y = rayon*sin(phase);
translate (x, y, 200+(50*5*n)); //
translate (100, 100, 200+(50*5*n));
colorMode(RGB, 255, 255, 255);
fill( 0, 255, 0 );
sphere(side*3);
popMatrix();
}
void follow( int target, int follower, int delais, float deltaphase) {
int step = frameCount % nbMaxDelais;
int followedStep = (step + nbMaxDelais - delais) % nbMaxDelais;
phases[follower][step] = diffAngle(phases[target][followedStep] + deltaphase, 0);
}
float diffAngle(float angle1, float angle2) { // return the difference angle1 - angle2 between two angle between -PI PI
float result = angle1 - angle2;
while (result > PI) {
result -= 2 * PI;
}
while (result < -PI) {
result += 2 * PI;
}
return result;
}
void keyPressed () {
if (keyCode == UP) {
frameRatio=frameRatio+5;
frameRatio=frameRatio%65;
if (frameRatio <=0 ){
frameRatio=5;
}
frameRate(frameRatio);
}
if (keyCode == DOWN) {
if (frameRatio <=5 ){
frameRatio=5;
}
frameRatio=frameRatio-1;
}
frameRate(frameRatio); // pas dans le void draw
if (keyCode == RIGHT) {
println(" right INCREASE timeOffset ") ; //
d+= 10; // incremente de demi sec. I need to increment 1282 to have 60 sec. So one sec is 1282/60 => 21.5 incrementations/sec
d=d%65;
print ("d= timeOffsetRatio: ");
println (d);
}
if (keyCode == LEFT) {
println(" left INCREASE phase shifting"); //
d-=10; // incremente de demi sec
}
}












