[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] Optimization Fun



On Wed, 2005-09-28 at 07:32 -0700, Simon Wittber wrote:
>         time_left = stop_time - now
>         yield 1 - ((cos((1.0 - time_left / duration) * pi) + 1) * 0.5)

You could use my favorite new algorithm for smoothing values between
0-1. It gets rid of the cos.


def smooth_normal_range_over_time(duration):
    now = time_func()
    stop_time = now + duration
	while now < stop_time:
	    percent = (stop_time - now) / duration
	    yield percent * percent * (3.0 - percent * 2.0)
	    now = time_func()
	yield 1.0


It's magically delicious. Also note, I like to always include a final
1.0 value on these types of generators. That way I ensure my animations
reach their final spot before stopping.

I would assume psyco would have good results on this type of code as
well.