|
Re: Optimization Fun: msg#00232python.pygame
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. |
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| Previous by Date: | Re: Optimization Fun: 00232, andrew baker |
|---|---|
| Next by Date: | Smooth scrolling ?: 00232, Dmitry Borisov |
| Previous by Thread: | Re: Optimization Funi: 00232, Simon Wittber |
| Next by Thread: | Re: Optimization Fun: 00232, Simon Wittber |
| Indexes: | [Date] [Thread] [Top] [All Lists] |
| News | FAQ | advertise |