Exemple #1
0
    public static Texture2D TextureFromMatrix(Vector2[,] matrix)
    {
        var normalized = matrix.Normalize();

        int width  = matrix.GetLength(0);
        int height = matrix.GetLength(1);

        // Create a map with all the pixels colors predefined (faster than applying each pixel one-by-one)
        var colorMap = new Color[width * height];

        for (int y = 0; y < height; y++)
        {
            for (int x = 0; x < width; x++)
            {
                // Assign the pixel a color based on its value
                float red = normalized[x, y].x;
                float blu = normalized[x, y].y;
                colorMap[y * width + x] = new Color(red, 0, blu);
            }
        }
        return(TextureFromColorMap(colorMap, width, height));
    }