Bonjour,
import peasy.*; PeasyCam cam; // change these for screen size float w = 600; float h = 600; // don't change these float w2 = w / 2; float h2 = h / 2; int nbBall = 10; //****************** FollowMovement int formerDecayTime, decayTime; int networkSize = 12; int NumberofStep = 6400; int formerFormerKey; int formerKey; float [] phaseFollowLFO= new float[networkSize]; // float [] oldPosF= new float[networkSize]; // float [] newPosF= new float[networkSize]; // float [] oldLfoPhase= new float[networkSize]; // float [] lfoPhase= new float[networkSize]; // float [] LFO= new float[networkSize]; // int [] DataToDueCircularVirtualPosition = new int[networkSize ]; //float [] phaseShiftingFollowLFO = new float[12]; float phaseShiftingFollowLFO; float timeLfo; int decayTimeLfo; int formerDecayTimeLfo; int [] rev = new int[networkSize]; // counter of revolution float [] newPosX = new float[12]; //; float [] oldPosX = new float[12]; //; char letter; boolean doA,doQ; int oscillatorChange; int decayTimeBis; int formerDecayTimeBis; int formerKeyMetro; float x,y,displacement,side; public void settings() { size(600, 600, P3D); } void setup(){ new PeasyCam(this, 2000); frameRate(30); formerFormerKey='#'; key='q'; } void draw() { background (0); lfoPattern(); if (key=='b' || key=='c') { formerKeyMetro = key; // choose mode to "follow" } if (formerKeyMetro == 'b' ){ splitTimeLfo(); if (key=='q' || key=='a') { letter = key; } switch(letter) { case 'q': doA=false; doQ=true; break; case 'a': doA=true; doQ=false; break; } if (formerFormerKey == '#') { // && doA==true // lfoPattern(); print (" normal " + frameCount + " lfoPhase[1] " + lfoPhase[1] + " lfoPhase[2] " + lfoPhase[2]); println ( ); for (int i = 2; i < networkSize-0; i+=1) { LFO[i] = lfoPhase[1]%TWO_PI; if (LFO[i]<0){ LFO[i] = phaseFollowLFO[i] - LFO[i]; DataToDueCircularVirtualPosition[i]= int (map (LFO[i], 0, -TWO_PI, NumberofStep, 0)); newPosX[i]= map (DataToDueCircularVirtualPosition[i], NumberofStep, 0, 0, -TWO_PI); } else LFO[i] = phaseFollowLFO[i] + LFO[i]; DataToDueCircularVirtualPosition[i]= (int) map (LFO[i], 0, TWO_PI, 0, NumberofStep); newPosX[i]= map (DataToDueCircularVirtualPosition[i], 0, NumberofStep, 0, TWO_PI); } if (LFO[oscillatorChange]<0){ LFO[oscillatorChange] = phaseFollowLFO[oscillatorChange]-LFO[oscillatorChange]; DataToDueCircularVirtualPosition[oscillatorChange]= int (map (LFO[oscillatorChange], 0, -TWO_PI, NumberofStep, 0)); newPosX[oscillatorChange]= map (DataToDueCircularVirtualPosition[oscillatorChange], NumberofStep, 0, 0, -TWO_PI); } else LFO[oscillatorChange] = phaseFollowLFO[oscillatorChange]+LFO[oscillatorChange]; DataToDueCircularVirtualPosition[oscillatorChange]= (int) map (LFO[oscillatorChange], 0, TWO_PI, 0, NumberofStep); newPosX[oscillatorChange]= map (DataToDueCircularVirtualPosition[oscillatorChange], 0, NumberofStep, 0, TWO_PI); } if (doQ==true ){ lfoPattern(); // followSignalLfo(frameRatio); // pendularPattern(); // offset with lfo oscillator by osillator print (" q " + frameCount + " "); print (" mov+LfoPhase "); println (LFO[oscillatorChange] ); for (int i = 2; i < networkSize-0; i+=1) { phaseFollowLFO[oscillatorChange]= PI/10*-oscillatorChange; // to understand // phaseFollowLFO[oscillatorChange]= lfoPhase[1]; LFO[oscillatorChange]= LFO[i]+phaseFollowLFO[i]; // add offset given by pendularPattern LFO[oscillatorChange]= LFO[i]%TWO_PI; if (LFO[i]<0){ DataToDueCircularVirtualPosition[i]= int (map (LFO[i], 0, -TWO_PI, NumberofStep, 0)); newPosX[oscillatorChange]= map (DataToDueCircularVirtualPosition[i], NumberofStep, 0, 0, -TWO_PI); // newPosX[i]= LFO[i]; } else DataToDueCircularVirtualPosition[i]= (int) map (LFO[i], 0, TWO_PI, 0, NumberofStep); newPosX[oscillatorChange]= map (DataToDueCircularVirtualPosition[i], 0, NumberofStep, 0, TWO_PI); } // } // doQ=false; key='#';// key='a'; // formerFormerKey = '#'; for (int i = 2; i < networkSize-0; i+=1) { drawBall(i, newPosX[i] ); println (" newPosX[i]" + newPosX[i] ); } countRevsCaseB(); for (int i = 2; i < networkSize-0; i+=1) { oldPosX[i]= newPosX[i] ; } } println(" formerFormerKey " + char (formerFormerKey) + " formerKey " + char (formerKey) + " key " + key) ; formerFormerKey= formerKey; formerKey=key; } void countRevsCaseB() { // ============================================= Ter NE PAS TOUCHER LE COMPTEUR ou Reduire l'espace avant et apres 0 pour eviter bug à grande vitesse for (int i = 0; i < networkSize; i++) { // decrement caused by negative angular velocity // both positive angles || both negative angles || positive-to-negative angle // if (//(net.oldPhase[i] < 0.25 * PI && net.phase[i] > 1.75 * PI) ||// if ( ((oldPosX[i] < 0.25 *PI && oldPosX[i]>0) && (newPosX[i] > -0.25* PI && newPosX[i] <0)) || (oldPosX[i] < -1.75 * PI && newPosX[i] > -0.25 * PI)// || ) { rev[i]--; } else { // if you do twice there is a funny bug // decompte[i] ++; // revolution[i]=0; } // increment caused by positive angular velocity // both positive angles || both negative angles || negative-to-positive angle if ( ((oldPosX[i] > -0.25 *PI && oldPosX[i]<0) && (newPosX[i] < 0.25* PI && newPosX[i] >0)) || (oldPosX[i] > 1.75 * PI && newPosX[i] < 0.25*PI) ) { rev[i]++; } else { } print (" revolution "); print ( i); print (" "); println (rev[i]); } } void splitTimeLfo() { if (formerDecayTimeLfo>decayTimeLfo){ oscillatorChange=oscillatorChange+1; // key='q'; } formerDecayTimeLfo = decayTimeLfo; int splitTimeLfo = millis()%200; // linear time to change " oscillator " each 200 ms oscillatorChange=oscillatorChange%12; if (oscillatorChange<=0) { oscillatorChange=2; } decayTimeLfo = splitTimeLfo; print (" oscillatorChange "); println ( oscillatorChange ); } void lfoPattern() { float signal1 = PI + (frameCount / 10.0) * cos (1000 / 500.0)*-1; float signal2 = PI + (frameCount / 11.0) * cos (1000 / 500.0)*-1; if (signal1 > 0 ) lfoPhase[1]= signal1%TWO_PI; // gauche droite vers le hau.t CIRCULAR MODE usefull ?// diffAngle(angle, HALF_PI);//% TWO_PI // position du point de depart + vitesse * phi constant ==> ici vitesse du point phases[0] est constante else lfoPhase[1]= signal1%TWO_PI; if (signal2 > 0 ) lfoPhase[2]= signal2%TWO_PI; // gauche droite vers le hau.t CIRCULAR MODE usefull ?// diffAngle(angle, HALF_PI);//% TWO_PI // position du point de depart + vitesse * phi constant ==> ici vitesse du point phases[0] est constante else lfoPhase[2]= signal2%TWO_PI; // print (" lfoPhase[1] "); print (lfoPhase[1]); print (" lfoPhase[2] "); println (lfoPhase[2]); } void drawBall(int n, float phase) { // print (n); print (" "); println (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(); }