Hi , i the following code i have an array and then i translate or move all the content of the array to the left then i put a new random number at the end of the array, for example if i have my array in this way:
[1, 1, 1, 1, 1] next state is gonna be [1, 1, 1, 1, 4] and next state is gonna be [1, 1, 1, 4, 8] and next state is gonna be [1, 1, 4, 8, 2] and so on. Im using this techniq to control an animation, so my question is how can i control the speed of this translation?
I found one way but it gives me a new problem, in this line:
nuevo_corre[i ] = corre[i + 1 ]; instead of adding to 1 i can change to 2 or more numbers to have more speed and in this way i can control the speed, but then i have the problem that it fill my array each 2 numbers so i end having something like this: [1, 1, 4, 1, 1, 8] , so the result is not very good
Any idea of how can i control the speed in a sucessfull way?
here is the code
Code:
float[] corre = new float[100];
float[] nuevo_corre = new float[100];
void setup(){
size(1200, 1200);
for(int i=0 ; i<100 ; i++){
corre[i]= 1; // first i fill my array with 1
nuevo_corre[i] = corre[i];
}
}
void draw(){
background(250, 250, 0);
if(keyPressed) {
for(int i=0 ; i<100 ; i++){
if(i < 56) {
nuevo_corre[i ] = corre[i + 1]; // please change the numerber 1 with 2 or 3
print(" " + nuevo_corre[i] );
}
else if (i ==56 ){
nuevo_corre[i] = random(121 );
}
}
for(int i=0 ; i<100 ; i++){
corre[i ] = nuevo_corre[i ];
ellipse( i * 5 , 20 , corre[i]/8 , corre[i]/8);
}
}
}