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 CSharpLightTask
- {
- class Program
- {
- static void Main(string[] args)
- {
- char symbol = '#';
- int value = 15;
- int maxValue = 20;
- DrawBar(symbol, value, maxValue, 0, 10);
- DrawBar('@', 11, 20, 0, 11, 50, color:ConsoleColor.Blue);
- Console.ReadKey();
- }
- static void DrawBar(char symbol, int value, int maxValue, int x, int y, int coloredPercent = 100 , ConsoleColor color = ConsoleColor.Red)
- {
- ConsoleColor defaultColor = Console.ForegroundColor;
- Console.SetCursorPosition(x, y);
- Console.ForegroundColor = defaultColor;
- Console.Write("[");
- string[] bar = new string[maxValue];
- for (int i = 0; i < bar.Length; i++)
- {
- if(i < (Convert.ToSingle(Convert.ToSingle(maxValue) / 100) * coloredPercent) - 1)
- {
- Console.ForegroundColor = color;
- }
- else
- {
- Console.ForegroundColor = defaultColor;
- }
- if (i < value)
- {
- Console.Write(symbol);
- }
- else if (bar[i] == null)
- {
- Console.Write(" ");
- }
- }
- Console.ForegroundColor = defaultColor;
- Console.Write("]");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement