Skip to content

Instantly share code, notes, and snippets.

@jplebre
Created December 8, 2015 14:49
Show Gist options
  • Select an option

  • Save jplebre/fc2979cf2d1f23f93c89 to your computer and use it in GitHub Desktop.

Select an option

Save jplebre/fc2979cf2d1f23f93c89 to your computer and use it in GitHub Desktop.
c# console line animation examples
using System;
namespace ConsoleAnimations
{
class MainClass
{
public static void Main(string[] args)
{
Animations spin = new Animations();
string loadingText = "Loading....";
Console.Write(loadingText);
Console.CursorVisible = false;
while (true)
{
spin.Turn(loadingText);
spin.SequencedMatrix(2,0,20,10);
spin.LoadingBar(loadingText,23, 0);
spin.Ready();
}
}
}
public class Animations
{
int counter;
public Animations()
{
counter = 0;
}
public void Turn(string loadingText)
{
Console.SetCursorPosition(loadingText.Length, 0);
switch (counter % 4)
{
case 0: Console.WriteLine("/"); break;
case 1: Console.WriteLine("-"); break;
case 2: Console.WriteLine("\\"); break;
case 3: Console.WriteLine("|"); break;
}
}
public void SequencedMatrix(int row, int column, int width, int height)
{
Console.SetCursorPosition(column, row);
int spot = counter % width;
int[,] array = new int[width,height];
for (int x = 0; x < array.GetLength(0); x++) {
for (int y = 0; y < array.GetLength(0); y++) {
if (y == spot)
{
Console.Write("[X]");
continue;
}
Console.Write("[ ]");
}
Console.WriteLine("");
}
}
public void LoadingBar(string loadingTest, int row, int column)
{
Console.SetCursorPosition(column, row);
string loadingText = loadingTest + " [";
string loadingTextTerminator = " ]";
Console.Write(loadingText+loadingTextTerminator);
for (int i = 0; i < counter % 20; i++)
{
if (counter == 0)
{
Console.SetCursorPosition(column, row);
Console.Write(loadingText+loadingTextTerminator);
}
Console.SetCursorPosition(loadingText.Length + i, row);
Console.Write("*");
}
}
public void Ready()
{
counter++;
System.Threading.Thread.Sleep(75);
}
}
}
@TDMAN-FS

Copy link
Copy Markdown

I’ve never seen a coding style like yours. I thought mine is weird enough.

@Rad1at3

Rad1at3 commented May 22, 2021

Copy link
Copy Markdown

nice

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment