View Single Post
Old 01-24-2013, 07:26 AM   PM User | #4
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,200
Thanks: 59
Thanked 3,996 Times in 3,965 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
I don't think you understand what this code is doing:
Code:
for (var timer = 0; timer < 10; timer++)
{
    setTimeout(function(){fade(timer, preciseResponseAverage, starResponseColor)}, 100);
}
That code is saying "Repeat 10 times: 100 milliseconds from *RIGHT NOW* call the fade function."

It is *NOT* saying "call the fade function 10 times, each time 100 milliseconds after the last".

So all 10 calls to fade( ) are being made...but they are *ALL* being made at essentially the same time.
So the human eye only sees the result of the last call.

But it would be trivial to have it do that:
Code:
for (var timer = 0; timer < 10; timer++)
{
    setTimeout(
        function(){ fade(timer, preciseResponseAverage, starResponseColor)}, 
        100*(timer+1)
    );
}
You see that?
The first call to fade will be at 100*(0+1) milliseconds.
The second call to fade will be at 100*(1+1) milliseconds.
...
The 10th call to fade will be at 100*(1+9) milliseconds, or 1 full second later.

Is this the best way to do it? Probably not. But it's workable.
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.

Last edited by Old Pedant; 01-24-2013 at 07:29 AM..
Old Pedant is offline   Reply With Quote