Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- internal class Program
- {
- static void Main(string[] args)
- {
- DrawBar(26, 10, ConsoleColor.Green, 0, 0);
- DrawBar(50, 15, ConsoleColor.Blue, 20, 0);
- Console.ReadKey();
- }
- static void DrawBar(int percent, int barLength, ConsoleColor color, int positionX, int positionY)
- {
- ConsoleColor defaultColor = Console.ForegroundColor;
- int minPercent = 0;
- int maxPercent = 100;
- char fillChar = '#';
- char emptyChar = '_';
- if (percent > maxPercent)
- {
- percent = maxPercent;
- }
- if (percent < minPercent)
- {
- percent = minPercent;
- }
- int filledCount = percent * barLength / maxPercent;
- int emptyCount = barLength - filledCount;
- Console.SetCursorPosition(positionX, positionY);
- Console.ForegroundColor = color;
- Console.Write('[');
- for (int i = 0; i < filledCount; i++)
- {
- Console.Write(fillChar);
- }
- for (int i = 0; i < emptyCount; i++)
- {
- Console.Write(emptyChar);
- }
- Console.Write(']');
- Console.ForegroundColor = defaultColor;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment