Advertisement
OldBeliver

Function_02

Mar 24th, 2021 (edited)
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.70 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
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             DisplayBar();
  14.  
  15.             Console.ReadKey();
  16.         }
  17.  
  18.         static void DisplayBar()
  19.         {
  20.             int currentValue = 40;
  21.             int maximumValue = 50;
  22.             int relativeSizeBar = 10;
  23.             int percent = currentValue * 100 / maximumValue;
  24.             int paintedBarSize = percent * relativeSizeBar / 100;
  25.  
  26.             string coloredPartOfBar = "";
  27.             string noColoredPartOfBar = "";            
  28.  
  29.             // header
  30.  
  31.             Console.Write($"Абсолютная длина полоски: ");
  32.             Console.Write($"{currentValue} это {percent}% от {maximumValue}, ");
  33.             Console.WriteLine($"закрашиваем {currentValue} ячеек из {maximumValue}.");
  34.  
  35.             // абсолютная полоска
  36.  
  37.             for (int i = 0; i < currentValue; i++)
  38.             {
  39.                 coloredPartOfBar += " ";
  40.             }
  41.  
  42.             Console.SetCursorPosition(0, 2);
  43.             Console.Write('[');
  44.             PaintBackground(coloredPartOfBar, ConsoleColor.DarkRed);            
  45.  
  46.             for (int i = currentValue; i < maximumValue; i++)
  47.             {
  48.                 noColoredPartOfBar += " ";
  49.             }
  50.  
  51.             Console.Write($"{noColoredPartOfBar}]");
  52.  
  53.             // относительная полоска
  54.  
  55.             coloredPartOfBar = "";
  56.             noColoredPartOfBar = "";
  57.  
  58.             Console.SetCursorPosition(0, 4);
  59.             Console.Write($"Относительная длина полоски: ");
  60.             Console.Write($"{currentValue} это {percent}% от {maximumValue}, ");
  61.             Console.WriteLine($"закрашиваем {paintedBarSize} ячеек из {relativeSizeBar}.");
  62.  
  63.             for (int i = 0; i < paintedBarSize; i++)
  64.             {
  65.                 coloredPartOfBar += " ";
  66.             }
  67.  
  68.             Console.Write('[');            
  69.             PaintBackground(coloredPartOfBar, ConsoleColor.DarkYellow);
  70.             for (int i = paintedBarSize; i < relativeSizeBar; i++)
  71.             {
  72.                 noColoredPartOfBar += " ";
  73.             }
  74.  
  75.             Console.Write($"{noColoredPartOfBar}]");
  76.         }
  77.  
  78.         static void PaintBackground(string text, ConsoleColor color)
  79.         {
  80.             ConsoleColor defaultColor = Console.BackgroundColor;
  81.             Console.BackgroundColor = color;
  82.             Console.Write(text);
  83.             Console.BackgroundColor = defaultColor;            
  84.         }
  85.     }
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement