Beispiel #1
0
        private static string GenerateDominanceMatrixOutput(RefreshVisualOutputEventArgs e, int maxLayers, bool colorDisplay)
        {
            string[,,] valueStrings      = new string[e.Dimensions[0], e.Dimensions[1], e.Dimensions[2] / 2];
            ConsoleColor[,,] valueColors = new ConsoleColor[e.Dimensions[0], e.Dimensions[1], e.Dimensions[2] / 2];

            for (int z = 0; z < e.Dimensions[2] / 2; z++)
            {
                for (int y = 0; y < e.Dimensions[1]; y++)
                {
                    for (int x = 0; x < e.Dimensions[0]; x++)
                    {
                        float frequency = e.Values[x, y, z * 2 + 0];
                        float value     = e.Values[x, y, z * 2 + 1];

                        if (colorDisplay)
                        {
                            byte[] rgb = ColorConverter.HSL2RGB(frequency / 2000.0f, 0.5, 0.5);
                            valueColors[x, y, z] = ColorConverter.ClosestConsoleColor(rgb[0], rgb[1], rgb[2]);
                        }

                        valueStrings[x, y, z] = $"{frequency.ToString("0.0")}Hz ({value.ToString(" +0.0000; -0.0000")})";
                    }
                }
            }

            // Console Content
            consoleSB.Clear();

            int displayLayers = Math.Min(maxLayers, e.Dimensions[2] / 2);

            for (int z = 0; z < displayLayers; z++)
            {
                PrintDominanceMatrixUnit(consoleSB, $"=== top {z+1} frequency", true, colorDisplay);
                PrintDominanceMatrixUnit(consoleSB, "+", false, colorDisplay);
                for (int x = 0; x < e.Dimensions[0]; x++)
                {
                    PrintDominanceMatrixUnit(consoleSB, "------------------------+", false, colorDisplay);
                }
                PrintDominanceMatrixUnit(consoleSB, null, true, colorDisplay);

                for (int y = 0; y < e.Dimensions[1]; y++)
                {
                    PrintDominanceMatrixUnit(consoleSB, "|", false, colorDisplay);
                    for (int x = 0; x < e.Dimensions[0]; x++)
                    {
                        PrintDominanceMatrixUnit(consoleSB, String.Format("{0,24}|", valueStrings[x, y, z]), false, colorDisplay, valueColors[x, y, z]);
                    }
                    PrintDominanceMatrixUnit(consoleSB, null, true, colorDisplay);

                    PrintDominanceMatrixUnit(consoleSB, "+", false, colorDisplay);
                    for (int x = 0; x < e.Dimensions[0]; x++)
                    {
                        PrintDominanceMatrixUnit(consoleSB, "------------------------+", false, colorDisplay);
                    }
                    PrintDominanceMatrixUnit(consoleSB, null, true, colorDisplay);
                }
            }

            return(consoleSB.ToString());
        }