views:

70

answers:

1

I've been experimenting with this and I haven't been able to come up with an adequate solution. Hoping one of you Mathletes can point me in the right direction. I'm building a Snow Globe in ActionScript 3 and I need to come up with a set of equations to control two level of snowflakes - one level random, and the other interactive where a user can click on them. For the random snow, I need to have it create certain number of random x/y positions at the bottom of the globe, which is a circle with a radius of around 300. Then when the shake action occurs, They should randomly float toward the top, then fall back to a random position at the bottom of the circle again.

For the interactive snow, I need it to randomly layout, but I don't want flakes to overlap so that its easier to interact with them.

A: 

Here is a solution, not particularly cleaver one though.

BAsed on the shape of your flake, you can compute how close a flake can get to another flake without overlapping (may require a particular rotation). Let that distance between the centers be d. Build a 2d array for your display at some resolution so that it contains your circle completely.

The array can have zero or 1 value. 0 means you can place a new snow flake there one means you cannot. Mark everything outside the circle as 1. Now pick a random center for the flake. When you place it there, mark out all points within d radius around it with 1. Generate another random point. If it is 1, continue to generate another random point till you find a 0. Once you find it, place the new snow flake there and mark everything around it with radius d. Some times when flakes are too close, you will have to rotate them appropriately so that they don't overlap.

Once you reach towards the end, it may start taking longer and longer to find a empty point. At this point you may want to scan the array, make a list of empty points and then just pick random points from there.