[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
Re: [pygame] Optimization Fun
Why does it have to be generated over time? Can't you have it
generate a list of values at once and send the list back to the
sprite? The sprite could then apply the change over time.
Or does this function appear within your sprite class?
On 9/28/05, Simon Wittber <simonwittber@xxxxxxxxx
> wrote:I use the below iterator to give me a smooth range of values between 0
and 1 over time. I use it to smoothly mooove sprites around. It is
very hard to optimize, because it always runs for a period of time,
and therefore, cannot be timed. Hmmm.
Anyone got any ideas on how to speed this iterator up, or test its
execution speed?
NB: time_func is defined as time.clock or time.time depending on platform.
Sw.
time_func = time.clock
def smooth_normal_range_over_time(duration):
"""
Provides a smooth (sine wave) progresion of values between 0.0 and
1.0 over a duration of seconds.
"""
stop_time = time_func() + duration
now = time_func()
while now < stop_time:
time_left = stop_time - now
yield 1 - ((cos((1.0 - time_left / duration) * pi) + 1) * 0.5)
now = time_func()
--
Andrew Ulysses Baker
"failrate"