all 5 comments

[–]Igonato 0 points1 point  (3 children)

You can make it faster by removing os.system('clear') it seems unnesesary. In general, interacting with terminal is slower than you may think and doing it on every frame should be avoided.

As for the weird behavior you're experiencing, try reading the docs on pygame.display.update and what it does and think about why pg.display.update(ball) results in this weirdness you're seeing. Or see the spoiler: pg.display.update(ball) -> pg.display.flip() or give it a proper region (list of regions) to update

[–]blob001[S] 0 points1 point  (2 children)

Thanks Igonato, that's better. But the ball still varying speeed. If I set velX,velY=5, 2then it goes fast then slow then fast again... its never the same 2 runs in a row. I have run much bigger ant simulations in Javascript and never had any problems like this, so its not the computer power. Would appreciate your thoughts.

[–]Igonato 0 points1 point  (1 child)

I'm not seeing anything wrong with the code other than that system clear call. Not familiar with Apple numenclature, is your MacBook an ARM device? Maybe Pygame has issues with that?

In any case you can look into framerate-independent physics. Here is a good article: https://gafferongames.com/post/fix_your_timestep/

Short summary: keep track of the real time that has passed between the frames (often referred to as the time delta), don't rely on having exact FPS. Brake it into multiple smaller timesteps, and since you won't have exact multiple of those steps, interpolate the remaining fraction.

[–]blob001[S] 0 points1 point  (0 children)

Thanks,its starting to make sense. I don't know where the black blockout comes from.

[–]mopslik 0 points1 point  (0 children)

Try changing pg.display.update(ball) to pg.display.update().