I have created a grid layout. It displays 100 balls. Initially, all the balls will be in a random position. Every 25 ms a ball will move some unit (this is common for all the balls) in a random direction. You can see this in action in the below image:
Even though the direction of the balls is random, after some time all the balls move towards the bottom right corner. This behavior repeats every time. You can see this in the below image:
C# Code
Random random = new Random();
var direction = random.NextDouble() * 360;
var ballTranslate = child.RenderTransform.TransformPoint(new Point(0, 0));
var x = ballTranslate.X;
var y = ballTranslate.Y;
var x1 = x + (parm.Speed * Math.Cos(direction));
while (x1 < 0 || x1 > (parm.CellSize * parm.NoOfSplit))
{
direction = random.NextDouble() * 360;
x1 = x + (parm.Speed * Math.Cos(direction));
}
var y1 = y + (parm.Speed * Math.Sin(direction));
while (y1 < 0 || y1 > (parm.CellSize * parm.NoOfSplit))
{
direction = random.NextDouble() * 360;
y1 = y + (parm.Speed * Math.Sin(direction));
}
TranslateTransform myTranslate = new TranslateTransform();
myTranslate.X = x1;
myTranslate.Y = y1;
child.RenderTransform = myTranslate;
Full Code
https://github.com/Vijay-Nirmal/ProjectChaos
You appear to be generating a direction in degrees and passing it to Math.Sin, which takes an angle in radians. 360/2PI = 57.3 (approximately), so you're slightly more likely to pick an angle between 0 and 0.3 radians than other, larger angles.
When you have so many iterations, it's also possible that there's a tiny rounding error somewhere
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With