r/programming • • Jun 25 '20

A bug with a surprisingly cool side effect

https://youtu.be/us1IqknNYmw
5.0k Upvotes

249 comments sorted by

View all comments

Show parent comments

28

u/anyonethinkingabout Jun 25 '20

no, you calculate the bubble sizes beforehand, before rendering

4

u/KillTrot Jun 25 '20

Well yes, thats a point. But still, you need an algorithm which self-corrects their path afterwards or am I missing smt?

13

u/anyonethinkingabout Jun 25 '20

no, you first generate the paths for the bubbles, then you enlarge every bubble such that they never touch when traveling on those paths

2

u/KillTrot Jun 25 '20

You mean you would make the collision in the beginning artificial and then with every collision you would artificially correct their path to the beforehand calculated one?

36

u/Piranha771 Jun 25 '20 edited Jun 25 '20

No.

  • You make a bunch of tiny tiny dots.

  • Now you let them orbit around the gravity center with random start positions/velocities (simulation).

  • Delete all tiny dots in simulation that collide.

  • Check for every tiny dot that is left, what was the nearest distance to any other dot during orbit. Increase the radius of tiny dot to that minimal distance.

  • Run simulation again with same positions/velocities but without the dots that had collision and with increased dot size as calculated.

EDIT: I know that it's not how it actually works. It was an answer to "How could I implement this, if I want that behavior on purpose"

33

u/efstajas Jun 25 '20 edited Jun 25 '20

Tbh it would probably be simpler to start with exclusively large dots and every time there is a hit, simply shave off exactly as much radius as is needed to prevent that collision the next time. If the dot becomes too tiny, delete it, just to make it not look messy.

If you reduce the radius instead of increasing, you get rid of the whole complexity of figuring out the maximum possible radius based on other dots orbits.

Anyway, both of these approaches might take quite a while to run if the system isn't periodic over a reasonable time-frame.

13

u/PezzzasWork Jun 25 '20

It could work I think. It is funny to see how complex it is compared to a bug :D

6

u/Salamander014 Jun 25 '20

That is a genius way of getting the same affect, but I would be much more interested in how the above actually works. The above comes from some sort of physics, the ball sizes are predetermined and the engine figures out the optimal paths. That is way more interesting than just forcefully generating this effect.

3

u/FVMAzalea Jun 25 '20

Wouldn’t you want to increase the radius by half of that tiny distance between them, at least in some cases? Because for the dot that you were minimally close to, it may form a pair where you were the dot that that dot was also minimally close to, so you’d both increase by the distance between you and end up colliding.

Unless it can be proven that no such pair will ever exist (which I don’t think is the case - I mean certainly not with just 2 dots for example because you’d always be minimally close to the other dot because there is no other option).

And then because you’re only increasing by half the distance, you wouldn’t be maximally big in the cases where you didn’t form a pair...maybe you could mitigate this by checking for pairs and adding half when you’re in a pair and full when you’re not which would add a little complexity to each dot calculation (O(the number of dots)) but not much.

2

u/soniiic Jun 25 '20

you're missing that at the start there is a collision at the centre, and then the dots all begin their non-colliding paths.