Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace UIElement_02
- {
- class Program
- {
- static void Main(string[] args)
- {
- int value = 12;
- int absoluteSize = 20;
- int relativeSize = 10;
- Console.SetCursorPosition(0, 0);
- Console.WriteLine($"Абсолютный размер полоски: ");
- Console.WriteLine($"закрашиваем {value} ячеек из {absoluteSize}");
- DisplayBar(value, absoluteSize);
- Console.SetCursorPosition(0, 4);
- Console.WriteLine($"Относительный размер полоски: ");
- Console.WriteLine($"{value} от {absoluteSize} это {value*100/absoluteSize}%. При размере полоски в {relativeSize} ячеек закрашиваем {value * relativeSize / absoluteSize} ячейки");
- DisplayBar(value, absoluteSize, relativeSize);
- Console.ReadKey();
- }
- static void DisplayBar(int value, int absoluteSize, char symbol = ' ')
- {
- string bar = "";
- for(int i = 0; i < value; i++)
- {
- bar += symbol;
- }
- Console.Write('[');
- PaintBackground(ref bar, ConsoleColor.DarkRed);
- bar = "";
- for (int i = value; i < absoluteSize; i++)
- {
- bar += symbol;
- }
- Console.WriteLine($"{bar}]");
- }
- static void DisplayBar(int value, int absoluteSize, int relativeSize, char symbol = ' ')
- {
- int coloredPercent = value * relativeSize / absoluteSize;
- string bar = "";
- for(int i = 0; i < coloredPercent; i++)
- {
- bar += symbol;
- }
- Console.Write('[');
- PaintBackground(ref bar, ConsoleColor.DarkRed);
- bar = "";
- for (int i = coloredPercent; i < relativeSize; i++)
- {
- bar += symbol;
- }
- Console.WriteLine($"{bar}]");
- }
- static void PaintBackground(ref string text, ConsoleColor color)
- {
- ConsoleColor defaultColor;
- defaultColor = Console.BackgroundColor;
- Console.BackgroundColor = color;
- Console.Write(text);
- Console.BackgroundColor = defaultColor;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement