炫酷的批处理BAT走字特效源码

先上第一版的代码,
代码肯定还存在BUG,先发上来给大家测试.

@echo off&setlocal enabledelayedexpansion
mode con: cols=87 lines=15
title code by foxjl 2007-12-1 www.jb51.net
color 1a
set long=43,minus=43
set,=^
我们,是一群执著的批处理爱好者^
在色彩斑斓的WINDOWS下,开启CMD这扇深邃的窗口^
曾经挑灯夜战,曾经彻夜不眠^
我们之所以如此似痴若狂,是因为我们深知:^
尺有所短、寸有所长,CMD不同凡响^
我们精益求精,力求完美^
所有的努力,只为了用最简洁的语言,编写最具实用性的代码^
安科网www.jb51.net^高手汇聚、资料齐全、是新手入门的福地、老手晋级的乐园^
不求最大、但求最好、展现批处理的无穷魅力、一切精彩,尽在~~安科网~~                 演示完毕。再见!!
:start
echo.
for %%i in (8 4 -1 4 -1 4 -1 10 -1 8 -1 16 -7 , 8 4 -1 4 -1 4 -1 10 -1 8 -1 8 -5 4 -1 4 -1 , 8 -4 2 -1 4 -1 10 -4 2 -1 12 -1 2 -7 , 8 4 -1 4 -1 4 -1 2 -1 6 -1 4 -1 2 -2 10 -1 2 -1 4 -1 4 -1 , 8 4 -1 4 -2 2 -2 6 -1 6 -1 2 -1 2 -1 4 -5 4 -1 4 -1 , 8 4 -2 2 -1 4 -1 8 -1 4 -1 4 -1 4 -1 6 -1 2 -7 , 8 -3 4 -1 4 -1 6 -1 2 -1 2 -1 4 -1 12 -1 8 -1 , 8 4 -1 4 -1 4 -1 12 -1 6 -1 12 -1 4 -5 , 8 4 -1 4 -1 2 -2 2 -1 8 -1 6 -1 12 -2 6 -1 , 8 4 -1 4 -2 2 -1 2 -1 6 -1 2 -2 2 -1 8 -2 10 -1 , 8 -3 4 -1 4 -3 2 -2 8 -5 8 -8) do (
(if "%%i"=="," (echo.&ping -n 1 127.1>nul)) && (set a=%%i)&(set b=!a:-=!)
 if %%i lss 0 (for /l %%j in (1,1,!b!) do (set/p=<nul)) else (for /l %%k in (1,1,%%i) do (set/p= <nul)
 )
)
call :delay 700
echo\&echo\
for /l %%z in (1,1,255) do (
if not !long! equ 0 set /a long-=1
for /l %%j in (1,1,87) do (set/p=<nul)
for /l %%k in (1,1,!long!) do (set/p= <nul)
set /a longn+=1
set /a longs=longn-43
set /a remnant=255-43
if !longn! lss 43 (set/p=!,:~0,%%z!<nul) else (
 if !longn! geq !remnant! (
  set /a minus-=1
  set /a minuss=minus*2
  for /l %%l in (1,1,!minus!) do (set/p= <nul)
  for /l %%j in (1,1,!minuss!) do (set/p=<nul)
  call set/p=%%,:~!longs!,43%%<nul
  ) else (
  call set/p=%%,:~!longs!,43%%<nul
  )
 )
call :delay 40 修改这个数字可以调整走字的速度.
)
call :delay 700&exit
:delay
for /l %%i in (1,1,%1) do (error>nul 2>nul)
goto :eof

动画效果很不错,象电视里的飞字幕.很有观赏性.

真是开了眼了 set ,=^ 再把每句最后加个^符号,就可以把它们都赋值给变量,?这是什么原理? 并且最后一句末尾又没有^符号?
不过,飞字幕部分,代码似乎可以更简洁.

来看看第二版的代码

:
@echo off&setlocal enabledelayedexpansion
title code by 泛滥慌° 2007-12-1 www.jb51.net
mode con: cols=87 lines=15
for /l %%l in (1 1 42) do set "ko= !ko!"
color 1a&echo\&set,=!ko!^
我们,是一群执著的批处理爱好者^
在色彩斑斓的WINDOWS下,开启CMD这扇深邃的窗口^
曾经挑灯夜战,曾经彻夜不眠^
我们之所以如此似痴若狂,是因为我们深知:^
尺有所短、寸有所长,CMD不同凡响^
我们精益求精,力求完美^
所有的努力,只为了用最简洁的语言,编写最具实用性的代码^
安科网www.jb51.net^高手汇聚、资料齐全、是新手入门的福地、老手晋级的乐园^
不求最大、但求最好、展现批处理的无穷魅力、一切精彩,尽在~~安科网~~                 演示完毕。再见!!
for %%i in (8 4 -1 4 -1 4 -1 10 -1 8 -1 16 -7 , 8 4 -1 4 -1 4 -1 10 -1 8 -1 8 -5 4 -1 4 -1 , 8 -4 2 -1 4 -1 10 -4 2 -1 12 -1 2 -7 , 8 4 -1 4 -1 4 -1 2 -1 6 -1 4 -1 2 -2 10 -1 2 -1 4 -1 4 -1 , 8 4 -1 4 -2 2 -2 6 -1 6 -1 2 -1 2 -1 4 -5 4 -1 4 -1 , 8 4 -2 2 -1 4 -1 8 -1 4 -1 4 -1 4 -1 6 -1 2 -7 , 8 -3 4 -1 4 -1 6 -1 2 -1 2 -1 4 -1 12 -1 8 -1 , 8 4 -1 4 -1 4 -1 12 -1 6 -1 12 -1 4 -5 , 8 4 -1 4 -1 2 -2 2 -1 8 -1 6 -1 12 -2 6 -1 , 8 4 -1 4 -2 2 -1 2 -1 6 -1 2 -2 2 -1 8 -2 10 -1 , 8 -3 4 -1 4 -3 2 -2 8 -5 8 -8) do (
(if "%%i"=="," (echo.&ping -n 1 127.1>nul)) && (set a=%%i)&(set b=!a:-=!)
 if %%i lss 0 (for /l %%j in (1,1,!b!) do (set/p=<nul)) else (for /l %%k in (1,1,%%i) do (set/p= <nul)
))
call :delay 700&echo\&echo\
for /l %%l in (1 1 255) do (
  set /p=!,:~0,43!<nul
  call :delay 40 修改这个数字可以调整走字的速度.
  for /l %%j in (1,1,87) do (set/p=<nul)
  set ,=!,:~1!
)
call :delay 700&exit
:delay
for /l %%i in (1,1,%1) do (error>nul 2>nul)
goto :eof

相关推荐