在控制台应用程序中,可以使用ASCII旋转器来指示正在执行的工作,就像GUI等待光标一样。常见的旋转器通过以下4个字符循环:'|','/','-','\'。
还有哪些循环动画序列可用于增添控制台应用程序的趣味性?
还有哪些循环动画序列可用于增添控制台应用程序的趣味性?
尝试这些操作符
在JavaScript中使用jQuery选择器:
var spins = [
"←↖↑↗→↘↓↙",
"▁▃▄▅▆▇█▇▆▅▄▃",
"▉▊▋▌▍▎▏▎▍▌▋▊▉",
"▖▘▝▗",
"┤┘┴└├┌┬┐",
"◢◣◤◥",
"◰ ◳ ◲ ◱",
"◴◷◶◵",
"◐◓◑◒",
"|/-\\"];
var spin = spins[0],
title$ = $('title'),
i=0;
setInterval(function() {
i = i==spin.length-1 ? 0 : ++i;
title$.text('('+ spin[i] +') Loading...');
},300);
很高兴我不是唯一一个浪费时间在这上面的疯子!
以下是我最喜欢的一些代码(某些使用了dos ASCII码):
classic: "/-\\|";
bouncing ball: ".oOo";
better bouncing ball: [46, 111, 79, 248, 79, 111]; // (.oO°Oo.)
[180, 217, 193, 192, 195, 218, 194, 191]; // ┤ ┘ ┴ └ ├ ┌ ┬ ┐
[185, 188, 202, 200, 204, 201, 203, 187]; // double piped version of that
[219, 220, 223]; // block colours
using System;
using System.Text;
using System.Threading;
namespace CSharpSandbox
{
class Program
{
static Random rnd = new Random();
static char[,] Step(char[,] matrix)
{
int width = matrix.GetUpperBound(0) + 1;
int height = matrix.GetUpperBound(1) + 1;
char[,] res = new char[width, height];
for (int h = 0; h < height; h++)
{
for (int w = 0; w < width; w++)
{
char c;
if (h == 0)
c = rnd.Next(2) == 0 ? ' ' : '*';
else
c = matrix[w, h - 1];
res[w, h] = c;
}
}
return res;
}
static string ToString(char[,] matrix)
{
int width = matrix.GetUpperBound(0) + 1;
int height = matrix.GetUpperBound(1) + 1;
StringBuilder sb = new StringBuilder();
for (int h = 0; h < height; h++)
{
for (int w = 0; w < width; w++)
{
sb.Append(matrix[w, h]);
}
sb.AppendLine();
}
return sb.ToString();
}
static Timer timer;
static void Spinner()
{
char[,] matrix = new char[10, 5];
timer = new Timer(_ =>
{
string s = ToString(matrix);
Console.SetCursorPosition(0, 0);
Console.Write(s);
matrix = Step(matrix);
},
null,
0,
200);
}
static void Main(string[] args)
{
Spinner();
Console.ReadLine();
}
}
}
Spinner()
中使用char[,] matrix = new char[Console.WindowWidth-1, Console.WindowHeight-1];
看起来很棒。 - Callum Rogers*
替换为 ,
以制造暴风雪。 - Sorin Comanescu感谢我的同事,这里提供了一个很棒的C语言实现:
#define COW 2172
char* moo = "MO ";
void wrap() {
int i,j;
for(i=0;doSomething(i);i++)
j=COW-moo[i&3],fputs(&j,stderr);
}
经过我的分析,它只能在至少有32位字长和ASCII字符集的小端机器上运行。但是,它相当地巧妙。
fputs((const char*)&j,stderr);
... 当它真的编译通过时,有点让人失望。 - EMP在一个应用程序中,我看到了1、2、3、4、5、6、7、8、9、0。
我写了一个循环显示标准的\ | / -,但是留下了一个_并继续移动到下一个位置。旨在看起来像一系列的旋转器,每个旋转器在下一个开始前都会掉落到地板上。这是因为我的程序正在重复尝试某些操作,等待特定的结果。我想表示每次尝试的次数以及尝试了多少次,而不占用太多屏幕空间(或计数器)。
写完后,它看起来比我想象中不那么酷,但它达到了它的目的。
我看过
echo -e "\033[41;1m$1 \033[0m"