|
Optimization Fun: msg#00230python.pygame
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() |
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| Previous by Date: | Re: PyGame slowdown: 00230, Simon Wittber |
|---|---|
| Next by Date: | Re: Optimization Fun: 00230, andrew baker |
| Previous by Thread: | PyGame slowdowni: 00230, Jason |
| Next by Thread: | Re: Optimization Fun: 00230, andrew baker |
| Indexes: | [Date] [Thread] [Top] [All Lists] |
| News | FAQ | advertise |