> I do not agree with the hiding the step() interface for Physics. You
> *need* to be able to provide the step duration there. Why? It is simple
> - your app has rarely constant framerate. If you couple the framerate to
> the physics sim in a fixed manner (e.g. one frame = one step), you are
> going to get problems with the physics, as each frame takes a slightly
> different amount of time.

This is true, however I have achieved a solution to both the above
problems using the below class. Using the default arguments, it will
count from 0 to 360 at a rate of 1 unit per second. Try it and see :-)
You could use this class to transparently supply the correct duration
value to the ste() function.

Sw.


class GovernedRange(object):
    """
    Returns values in range, with each successive value incremented at
    a set speed rather than value.
    """
    def __init__(self, speed=1, low=0, high=359):
        self.speed = float(speed)
        self.low = float(low)
        self.high = float(high)
        self._i = self.low
        self._t = time.time()
    
    def __iter__(self):
        while True:
            yield self.next()
            
    def next(self):
        i = self._i
        speed = float(self.speed)
        inc = speed * (time.time() - self._t)
        i += inc
        i = i % self.high
        self._t = time.time()
        self._i = i
        return i

if __name__ == "__main__":
    for v in GovernedRange():
        print v

Reply via email to