Advertisement
OldBeliver

Function_02ver05

Mar 28th, 2021
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.62 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace UIElement_03
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             int value = 12;
  14.             int maxValue = 20;
  15.             int relativeSize = 100;
  16.            
  17.             DisplayBar(value, maxValue, relativeSize);
  18.  
  19.             Console.ReadKey();
  20.         }
  21.  
  22.         static void DisplayBar(int value, int maxValue, int relativeSize, char symbol = ' ')
  23.         {
  24.             int percent = value * 100 / maxValue;
  25.             int coloredPercent = value * relativeSize / maxValue;
  26.  
  27.             Console.SetCursorPosition(0, 1);
  28.             Console.WriteLine($"Относительный размер полоски: ");
  29.             Console.WriteLine($"{value} от {maxValue} это {percent}%. При размере полоски в {relativeSize} ячеек, закрашиваем {coloredPercent} из них.");
  30.  
  31.             string bar = "";
  32.  
  33.             for (int i = 0; i < coloredPercent; i++)
  34.             {
  35.                 bar += symbol;
  36.             }
  37.  
  38.             Console.Write('[');
  39.            
  40.             ConsoleColor defaultColor;
  41.             defaultColor = Console.BackgroundColor;
  42.             Console.BackgroundColor = ConsoleColor.DarkRed;
  43.             Console.Write(bar);
  44.             Console.BackgroundColor = defaultColor;
  45.  
  46.             bar = "";
  47.             for (int i = coloredPercent; i < relativeSize; i++)
  48.             {
  49.                 bar += symbol;
  50.             }
  51.  
  52.             Console.WriteLine($"{bar}]");
  53.         }
  54.     }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement