[Tutor] What's the error (program)
Emmanuel Ruellan
eruellan@iFrance.com
Wed Nov 6 17:30:02 2002
Alex Gillis wrote:
>OK, here is the recently annotated program thats causing
>problems. [...]
Hi Alex,
I've had a look at your juggling simulator, tried to modify some
things and managed to get a decent animation of a 3-ball cascade.
I'm a beginner at programming as well, but I've got an interest
in siteswap. Here's what I've done.
In your program, each fraction of a second, the velocity of each
ball in the air is modified because of gravity:
> ball.velocity.y = ball.velocity.y - 10*dt
Fine. But you forgot to modify the ball's position according to
its velocity. I've inserted this function:
def move(ball):
ball.pos = ball.pos + ball.velocity * dt
...as well as instructions like...
move(balln)
...for each ball, in the main while loop.
But that wasn't enough to get the program to work, so I also
applied Magnus' advice not to compare floats on equality and modified
the 'throwcatch' function accordingly, with conditions like:
elif -0.1 - epsilon < ball.pos.x < -0.1 + epsilon:
(For the sake of aestethics and realism, I've changed the formula
for horizontal velocity as well ;) -- I'm sending comment on the
juggling issues to your mailbox.)
I've found another error that doesn't show in the 3-ball cascade,
though. After incrementing i, don't forget to modifiy next_value
as well by:
next_value = siteswap[i]
...otherwise, there's no point in incrementing i.
Talking of incrementation, you can write :
i = (i + 1) % 3
instead of
> i = i + 1
>
> if i == 3:
> i = 0
Regards,
Manu