• 0

[c#] Random spacing algorithm


Question

Hey gang,

I am in need of a pattern algorithm that i can use as i am loading a window with ellipses that are animating right to left, but not on the y axis. The Y axis is set when the ellipse loads. There are a number of random pieces to each ellipse so im trying to avoid too much grouping. Any thought?

Link to comment
Share on other sites

5 answers to this question

Recommended Posts

  • 0

Tried with WPF animations?

I am using WPF. What I am looking for is an algorithm that will allow me to space the ellipses randomly in the Y axis without crowding them all in one range. IE: I have 0 to 1000, but I don't want all ellipses to end up in the 0 to 200.

Does that clarify?

Link to comment
Share on other sites

  • 0

Hey gang,

I am in need of a pattern algorithm that i can use as i am loading a window with ellipses that are animating right to left, but not on the y axis. The Y axis is set when the ellipse loads. There are a number of random pieces to each ellipse so im trying to avoid too much grouping. Any thought?

How about dividing the axis into segments, and randomly allocating a single ellipse to each segment. The randomisation algorithm would allocate a blank ellipse to some segments.

Link to comment
Share on other sites

  • 0

Yea, I have thought about making 8 or 10 sections and then keeping a list of how many ellipses are within any section to keep the spread even. I was hoping to find an existing algorithm that will do the work.

Thanks for the thought.

Link to comment
Share on other sites

  • 0

So you don't want anything random at all (otherwise your objective, placing ellipses along the entire axis, makes no sense). If you wanted random numbers, you would want to generate a uniform distribution; but that provides no guarantee that the ellipses won't be bunched up (since random numbers, by definition, have absolutely no guarantee about their distribution in a range. In other words, if you're generating pseudorandom numbers in the range 0 - 1000, there's no way to guarantee that they won't all end up in the range 0 - 100 without introducing bias). The C++11 standard has a Random spec that allows for introducing these kinds of biases. I'm sure there's a C# library to do so, but I'm pretty sure the .NET Framework doesn't have something like that natively.

One way to do what you want is to divide your range (0-1000) into N blocks (where N is the number of ellipses). Then for each block, generate a pseudorandom spot in that block's range and place an ellipse there. Then move to the next block. This is pretty much what Ntrstd said.

So if you have 10 ellipses, generate a number between 0 and 100 and place an ellipse there. Then generate a number between 100 and 200 and place an ellipses there... and so on. No need to keep track of occupied positions and it guarantees a biased, relatively-even distribution. It also doesn't require some third-party library.

Alternatively, you could put, say, 5 of those 10 ellipses in the above quasi-even distribution and then place the rest anywhere in the range (0-1000) by generating uniformly-distributed pseudorandom numbers in that entire range.

Link to comment
Share on other sites

  • 0

Thanks for the thoughts. I am hoping to avoid TOO many ellipses within an area but you are correct, I can have random or not. I was leaning toword segmenting the Y axis into a number of groups (less than 10) and keep track of the number within that section to avoid such large groupings.

I will review what you wrote and think it over.

Thank you very much.

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.