[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[pygame] Optimization Fun
- To: pygame-users@xxxxxxxx
- Subject: [pygame] Optimization Fun
- From: Simon Wittber <simonwittber@xxxxxxxxx>
- Date: Wed, 28 Sep 2005 07:32:47 -0700
- Delivered-to: archiver@seul.org
- Delivered-to: pygame-users-outgoing@seul.org
- Delivered-to: pygame-users@seul.org
- Delivery-date: Wed, 28 Sep 2005 10:33:00 -0400
- Domainkey-signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:reply-to:to:subject:mime-version:content-type:content-transfer-encoding:content-disposition; b=HfhQL3hFHmi5zDGdQWkMtKdt5LfbsNEsh6N8dEuZWM2bDgfbNW+j9OSiHj0/nP+tHR9eByZlZUIoBtnqgvtOKTFwKB67uHL+/dwgA3P27DsZIORPYhlSkmBa4pu3HZ/2wZJZxiQoEmKUAfmxyUeyl4OdvHOWg+JSUefrBaZHiyU=
- Reply-to: pygame-users@xxxxxxxx
- Sender: owner-pygame-users@xxxxxxxx
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()