CSharpGL.Ground.GenerateColors C# (CSharp) Method

GenerateColors() private method

private GenerateColors ( int squreCountPerUnit, int xUnit, int zUnit ) : vec3[]
squreCountPerUnit int
xUnit int
zUnit int
return vec3[]
        private vec3[] GenerateColors(int squreCountPerUnit, int xUnit, int zUnit)
        {
            var colors = new vec3[
                (xUnit * 2 * squreCountPerUnit + 1) * 2
                + (zUnit * 2 * squreCountPerUnit + 1) * 2
                ];
            int index = 0;
            for (int i = 0; i < xUnit * 2 * squreCountPerUnit + 1; i++)
            {
                if (i % squreCountPerUnit == 0)
                {
                    colors[index++] = new vec3(1,
                        Math.Abs((float)(i) / (float)(xUnit * 2 * squreCountPerUnit) * 2 - 1.0f),
                        0);
                    colors[index++] = new vec3(1,
                        Math.Abs((float)(i) / (float)(xUnit * 2 * squreCountPerUnit) * 2 - 1.0f),
                        0);
                }
                else
                {
                    colors[index++] = new vec3(1, 1, 1);
                    colors[index++] = new vec3(1, 1, 1);
                }
            }
            for (int i = 0; i < zUnit * 2 * squreCountPerUnit + 1; i++)
            {
                if (i % squreCountPerUnit == 0)
                {
                    colors[index++] = new vec3(0,
                        Math.Abs((float)(i) / (float)(xUnit * 2 * squreCountPerUnit) * 2 - 1.0f),
                        1);
                    colors[index++] = new vec3(0,
                        Math.Abs((float)(i) / (float)(xUnit * 2 * squreCountPerUnit) * 2 - 1.0f),
                        1);
                }
                else
                {
                    colors[index++] = new vec3(1, 1, 1);
                    colors[index++] = new vec3(1, 1, 1);
                }
            }

            return colors;
        }