I have an array of pixels which make up a 2D grid and I want to move these pixels right and left over time... constantly however the loop I came up with is fairly inefficient and does not allow for much expansion in terms of changing the motion. Any ideas on how to improve what I already have would be much appreciated.
while (true)
{
for (float i = 0; i < x; i++)
{
foreach (Pixel p in pixels)
{
p.move(10, 0);
}
}
for (float i = 0; i < x * 2; i++)
{
foreach (Pixel p in pixels)
{
p.move(-10, 0);
}
}
for (float i = 0; i < x; i++)
{
foreach (Pixel p in pixels)
{
p.move(10, 0);
}
}
}
Edit: Sorry had an error in the code the middle loop needed to be -10 the first for loop moves all the pixels right, the second moves them back to the origin and then to the left, the third loop then moves them back to the origin.