Mathematical equations of random snow in a snow globe

I experimented with this, and I could not find an adequate solution. Hoping that one of you, Mats, can point me in the right direction. I am creating a Snow Globe in ActionScript 3, and I need to come up with a set of equations to control two levels of snowflakes - one level is random and the other is interactive, where the user can click on them. For random snow, I need to create a certain number of random x / y positions in the lower part of the globe, which is a circle with a radius of about 300. Then, when the action of shaking occurs, they should randomly swim in the direction, then return to the random position at the bottom again circle.

For interactive snow, I need this in random order, but I do not want the scales to overlap, so that it is easier to interact with them.

+4
source share
1 answer

Here is a solution, but not particularly cropped.

BAsed from the shape of your flake, you can calculate how close flakes can get to another flake without overlapping (specific rotation may be required). Let this distance between the centers be equal to d. Create a 2d array for your display with some resolution so that it fully contains your circle.

Array can have zero or 1 value. 0 means you can put a new snow scale there, so you cannot. Mark everything outside the circle as 1. Now select a random center for the flake. When you place it there, mark all the points inside the radius d around it with 1. Create another random point. If it is 1, continue to generate another random point until you find 0. When you find it, put a new snow flake there and mark everything around with a radius d. Sometimes, when the scales are too close, you will have to rotate them accordingly so that they do not overlap.

Once you reach the end, he can begin to take more and more to find an empty point. At this point, you can scan the array, make a list of empty points, and then just select random points from there.

0
source

All Articles