Advertisement
OldBeliver

Function_02ver02

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