Ejemplo n.º 1
0
    /// <summary>
    /// Writes the specified chemistry periodic table, followed by the current line terminator, to the standard output stream.
    /// </summary>
    /// <param name="console">The console instance.</param>
    /// <param name="style">The style.</param>
    public static void WriteTable(StyleConsole console, ChemicalElementConsoleStyle style)
    {
        var col = new List <ConsoleText>();

        if (style == null)
        {
            style = new();
        }
        var symbolStyle = new ConsoleTextStyle
        {
            ForegroundConsoleColor = style.SymbolConsoleColor,
            ForegroundRgbColor     = style.SymbolRgbColor,
            BackgroundConsoleColor = style.BackgroundConsoleColor,
            BackgroundRgbColor     = style.BackgroundRgbColor
        };
        var numberStyle = new ConsoleTextStyle
        {
            ForegroundConsoleColor = style.AtomicNumberConsoleColor,
            ForegroundRgbColor     = style.AtomicNumberRgbColor,
            BackgroundConsoleColor = style.BackgroundConsoleColor,
            BackgroundRgbColor     = style.BackgroundRgbColor
        };
        var punctuationStyle = new ConsoleTextStyle
        {
            ForegroundConsoleColor = style.PunctuationConsoleColor,
            ForegroundRgbColor     = style.PunctuationRgbColor,
            BackgroundConsoleColor = style.BackgroundConsoleColor,
            BackgroundRgbColor     = style.BackgroundRgbColor
        };

        col.Add("1 ", punctuationStyle);
        AppendSymbol(col, ChemicalElement.H, symbolStyle);
        col.Add(' ', 64, punctuationStyle);
        AppendSymbol(col, ChemicalElement.He, symbolStyle);
        col.AddNewLine();
        col.Add("  ", punctuationStyle);
        AppendNumber(col, 1, numberStyle);
        col.Add(' ', 64, punctuationStyle);
        AppendNumber(col, 2, numberStyle);
        col.AddNewLine();
        col.AddNewLine();

        col.Add("2 ", punctuationStyle);
        AppendSymbol(col, ChemicalElement.Li, symbolStyle);
        AppendSymbol(col, ChemicalElement.Be, symbolStyle);
        col.Add(' ', 40, punctuationStyle);
        AppendSymbol(col, ChemicalElement.B, symbolStyle);
        AppendSymbol(col, ChemicalElement.C, symbolStyle);
        AppendSymbol(col, ChemicalElement.N, symbolStyle);
        AppendSymbol(col, ChemicalElement.O, symbolStyle);
        AppendSymbol(col, ChemicalElement.F, symbolStyle);
        AppendSymbol(col, ChemicalElement.Ne, symbolStyle);
        col.AddNewLine();
        col.Add("  ", punctuationStyle);
        AppendNumber(col, 3, numberStyle, 2);
        col.Add(' ', 40, punctuationStyle);
        AppendNumber(col, 5, numberStyle, 6);
        col.AddNewLine();
        col.AddNewLine();

        col.Add("3 ", punctuationStyle);
        AppendSymbol(col, ChemicalElement.Na, symbolStyle);
        AppendSymbol(col, ChemicalElement.Mg, symbolStyle);
        col.Add(' ', 40, punctuationStyle);
        AppendSymbol(col, ChemicalElement.Al, symbolStyle);
        AppendSymbol(col, ChemicalElement.Si, symbolStyle);
        AppendSymbol(col, ChemicalElement.P, symbolStyle);
        AppendSymbol(col, ChemicalElement.S, symbolStyle);
        AppendSymbol(col, ChemicalElement.Cl, symbolStyle);
        AppendSymbol(col, ChemicalElement.Ar, symbolStyle);
        col.AddNewLine();
        col.Add("  ", punctuationStyle);
        AppendNumber(col, 11, numberStyle, 2);
        col.Add(' ', 40, punctuationStyle);
        AppendNumber(col, 13, numberStyle, 6);
        col.AddNewLine();
        col.AddNewLine();

        col.Add("4 ", punctuationStyle);
        for (var i = 19; i <= 36; i++)
        {
            AppendSymbol(col, ChemicalElement.Get(i), symbolStyle);
        }

        col.AddNewLine();
        col.Add("  ", punctuationStyle);
        AppendNumber(col, 19, numberStyle, 18);
        col.AddNewLine();
        col.AddNewLine();

        col.Add("5 ", punctuationStyle);
        for (var i = 37; i <= 54; i++)
        {
            AppendSymbol(col, ChemicalElement.Get(i), symbolStyle);
        }

        col.AddNewLine();
        col.Add("  ", punctuationStyle);
        AppendNumber(col, 37, numberStyle, 18);
        col.AddNewLine();
        col.AddNewLine();

        col.Add("6 ", punctuationStyle);
        for (var i = 55; i < 58; i++)
        {
            AppendSymbol(col, ChemicalElement.Get(i), symbolStyle);
        }

        for (var i = 72; i <= 86; i++)
        {
            AppendSymbol(col, ChemicalElement.Get(i), symbolStyle);
        }

        col.AddNewLine();
        col.Add("  ", punctuationStyle);
        AppendNumber(col, 55, numberStyle, 2);
        col.Add("... ", punctuationStyle);
        AppendNumber(col, 72, numberStyle, 15);
        col.AddNewLine();
        col.AddNewLine();

        col.Add("7 ", punctuationStyle);
        for (var i = 87; i < 90; i++)
        {
            AppendSymbol(col, ChemicalElement.Get(i), symbolStyle);
        }

        for (var i = 104; i <= 118; i++)
        {
            AppendSymbol(col, ChemicalElement.Get(i), symbolStyle);
        }

        col.AddNewLine();
        col.Add("  ", punctuationStyle);
        AppendNumber(col, 87, numberStyle, 2);
        col.Add("... ", punctuationStyle);
        AppendNumber(col, 104, numberStyle, 15);
        col.AddNewLine();
        col.AddNewLine();

        col.Add(ChemicalElement.La.Symbol, symbolStyle);
        col.Add('-', 1, punctuationStyle);
        col.Add(ChemicalElement.Lu.Symbol, symbolStyle);
        col.Add("\t  ", punctuationStyle);
        for (var i = 57; i <= 71; i++)
        {
            AppendSymbol(col, ChemicalElement.Get(i), symbolStyle);
        }

        col.AddNewLine();
        col.Add("\t  ", punctuationStyle);
        AppendNumber(col, 57, numberStyle, 15);
        col.AddNewLine();
        col.AddNewLine();

        col.Add(ChemicalElement.Ac.Symbol, symbolStyle);
        col.Add('-', 1, punctuationStyle);
        col.Add(ChemicalElement.Lr.Symbol, symbolStyle);
        col.Add("\t  ");
        for (var i = 89; i <= 103; i++)
        {
            AppendSymbol(col, ChemicalElement.Get(i), symbolStyle);
        }

        col.AddNewLine();
        col.Add("\t  ", punctuationStyle);
        AppendNumber(col, 89, numberStyle, 15);
        col.AddNewLine();
        col.AddNewLine();

        if (ChemicalElement.Has(119) && ChemicalElement.Has(120))
        {
            col.Add("8 ", punctuationStyle);
            col.Add("119 ", numberStyle);
            col.Add('-', 1, punctuationStyle);
            col.Add(" 168 ", numberStyle);
            AppendSymbol(col, ChemicalElement.Get(119), symbolStyle);
            AppendSymbol(col, ChemicalElement.Get(120), symbolStyle);
            for (var i = 121; i < 131; i++)
            {
                if (ChemicalElement.Has(i))
                {
                    AppendSymbol(col, ChemicalElement.Get(i), symbolStyle);
                }
                else
                {
                    break;
                }
            }

            col.Add("...", punctuationStyle);
            col.AddNewLine();
        }
        else
        {
            col.Add("8 ", punctuationStyle);
            col.Add("119 ", numberStyle);
            col.Add('-', 1, punctuationStyle);
            col.Add(" 168 ", numberStyle);
            col.AddNewLine();
        }

        col.Add("9 ", punctuationStyle);
        col.Add("169 ", numberStyle);
        col.Add('-', 1, punctuationStyle);
        col.Add(" 218 ", numberStyle);
        col.AddNewLine();

        (console ?? StyleConsole.Default).Write(col);
    }