使用 Perl 來完成一則文字逐字顯示的動畫悴晰。
use Win32::Console;
use Encode;
use 5.010;
use AnyEvent;
use Win32::Console::ANSI;
use Term::ANSIColor;
my @color = qw( red green yellow blue magenta cyan white
bright_black bright_red bright_green bright_yellow
bright_blue bright_magenta bright_cyan bright_white ansi0);
#my @color= map {'ansi'.$_} (0..15);
$|=1; #必須開啟這個
system("mode con cols=135 lines=25");
my $Out = new Win32::Console(STD_OUTPUT_HANDLE) || die;
my $cv = AnyEvent->condvar;
my $count=0;
my $w; $w = AnyEvent->timer(
after => 2,
interval => 1,
cb => sub {
$count++;
my ( $x, $y ) = $Out->Cursor();
$Out->Cursor( $x+125, $y + 5,0,0);
while (<DATA>) {
s/ / /g;
chomp;
$a=decode('gb2312',$_);
@words=$a=~m/(.)/g;
foreach $word (@words) {
$c = $color[int rand @color];
print color 'bold '.$c;
$Out->Write(encode('gb2312',$word));
my ( $x, $y ) = $Out->Cursor();
$Out->Cursor( $x, $y + 1,0,1);
my ( $x, $y ) = $Out->Cursor();
$Out->Cursor( $x-2, $y,0,1);
select(undef,undef,undef,0.045);
}
my ( $x, $y ) = $Out->Cursor();
$Out->Cursor( $x-2, $y-@words,0,0);
}
# system("cls");
# say $count;
seek(DATA,1565,0); # 句柄讀到最后了就沒有文本了嘴高,所以需要返回,其實DATA就是整個文件,是這個script的所有文本。
if ($count >= 1) {
undef $w;
}
}
);
$cv->recv;
__END__
星月神話
我的一生最美好的場景
就是遇見你
在人海茫茫中靜靜凝望著你
陌生又熟悉
盡管呼吸著同一天空的氣息
卻無法擁抱到你
如果轉換了時空身份和姓名
但愿認得你眼睛
千年之后的你會在哪里
身邊有怎樣風景
我們的故事并不算美麗
卻如此難以忘記
盡管呼吸著同一天空的氣息
卻無法擁抱到你
如果轉換了時空身份和姓名
但愿認得你眼睛
千年之后的你會在哪里
身邊有怎樣風景
我們的故事并不算美麗
卻如此難以忘記
如果當初勇敢的在一起
會不會不同結局
你會不會也有千言萬語
埋在沉默的夢里