We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › controlling speed in translation: content of array
Page Index Toggle Pages: 1
controlling speed in translation: content of array (Read 702 times)
controlling speed in translation: content of array
Sep 5th, 2009, 6:16pm
 
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);
}
}
}




Re: controlling speed in translation: content of array
Reply #1 - Sep 6th, 2009, 1:47am
 
That's a classical problem. People tend to do a for loop in draw() to get a progressive effect, while the Processing way is to use regular calls of draw() (by Processing itself) to do the loop (you have to maintain a global counter as loop index).
To control speed, you can count frames or watch millis() - startTime going over a fixed value.
Re: controlling speed in translation: content of array
Reply #2 - Sep 6th, 2009, 5:57am
 
hi philLo i thought in what you say, but that problem with that idea i just can make the translation of the array slower but not faster, and i need to make it faster. Any idea?

Re: controlling speed in translation: content of array
Reply #3 - Sep 6th, 2009, 7:21am
 
Increase the frame rate...
Or make bigger moves.
Re: controlling speed in translation: content of array
Reply #4 - Sep 6th, 2009, 7:35am
 
hi i cant increase the framerate because i need to use my array to scale animated array and making bigger moves was the first thing ive tried but i get holes in my array , if i make nuevo_corre[i ] = corre[i + 4 ]; instead of nuevo_corre[i ] = corre[i + 1 ];  i get  [1 , 0, 0, 0, 2 , 0, 0 , 0, 3, 0, 0, 0, 4...and so on, and i need [1, 2, 3, 4 ...
Page Index Toggle Pages: 1