只需使用Console.SetCursorPosition
将光标移动到某个位置,然后Console.Write
一个人物。在每一帧之前,您必须通过用空格覆盖前一帧来删除它。这是我刚刚构建的一个小例子:
class Program
{
static void Main(string[] args)
{
char[] chars = new char[] { '.', '-', '+', '^', '°', '*' };
for (int i = 0; ; i++)
{
if (i != 0)
{
// Delete the previous char by setting it to a space
Console.SetCursorPosition(6 - (i-1) % 6 - 1, Console.CursorTop);
Console.Write(" ");
}
// Write the new char
Console.SetCursorPosition(6 - i % 6 - 1, Console.CursorTop);
Console.Write(chars[i % 6]);
System.Threading.Thread.Sleep(100);
}
}
}
例如,您可以拍摄一个 gif 动画,从中提取所有单帧/图像(请参阅如何执行此操作)here http://www.vcskicks.com/csharp_animated_gif2.php),应用 ASCII 转换(描述了如何做到这一点here http://www.c-sharpcorner.com/UploadFile/dheenu27/ImageToASCIIconverter03022007164455PM/ImageToASCIIconverter.aspx例如)并像上面的代码示例一样逐帧打印这些内容。
Update
只是为了好玩,我实现了我刚才描述的内容。更换一下试试@"C:\some_animated_gif.gif"
以及一些(不是很大)动画 gif 的路径。例如,从以下位置获取 AJAX 加载器 gifhere http://ajaxload.info/.
class Program
{
static void Main(string[] args)
{
Image image = Image.FromFile(@"C:\some_animated_gif.gif");
FrameDimension dimension = new FrameDimension(
image.FrameDimensionsList[0]);
int frameCount = image.GetFrameCount(dimension);
StringBuilder sb;
// Remember cursor position
int left = Console.WindowLeft, top = Console.WindowTop;
char[] chars = { '#', '#', '@', '%', '=', '+',
'*', ':', '-', '.', ' ' };
for (int i = 0; ; i = (i + 1) % frameCount)
{
sb = new StringBuilder();
image.SelectActiveFrame(dimension, i);
for (int h = 0; h < image.Height; h++)
{
for (int w = 0; w < image.Width; w++)
{
Color cl = ((Bitmap)image).GetPixel(w, h);
int gray = (cl.R + cl.G + cl.B) / 3;
int index = (gray * (chars.Length - 1)) / 255;
sb.Append(chars[index]);
}
sb.Append('\n');
}
Console.SetCursorPosition(left, top);
Console.Write(sb.ToString());
System.Threading.Thread.Sleep(100);
}
}
}