|
无奈何
荣誉版主
      
积分 1338
发帖 356
注册 2005-7-15
状态 离线
|
 『楼 主』:
[推荐][挑战思路]用脚本模拟黑客帝国数码雨
使用 LLM 解释/回答一下
近日看到一段用 PHP 制作的脚本,模拟了黑客帝国里数码雨的效果,很炫。遗憾的是我将脚本保存后,忘了保存作者的主页,搜索也没有结果,所以我也不知道作者是谁了。
我尝试用纯批处理来实现,始终没有成功。鉴于大家机器上不可能都安装有 PHP ,我将其转换成了 awk 脚本,可以更方便的先体验一下效果。
看看兄弟们那位能用批处理来实现。
awk 版:
保存为批处理执行。
@echo off
mode con cols=80
color 02
gawk "/^#<-1/,/^#>-1/{if(!/^#/)print}" "%~f0" |gawk -f "-" %*
goto :EOF
:AwkScript
#<-1
function mt_rand(a,b) {
return int(((rand()*(1+b-a))+a))
}
BEGIN{
iWidth = 80
iDensity = 4
sText = "1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ~`!@#%^&*(){}_+-=\\\"'|<>?.,/"
iText = length(sText) - 1
for (i = 0; i < iWidth; i++) {
aDown = 0
}
for (;;) {
for (i = 0; i < iWidth; i++) {
aDown--
if (aDown < 0) {
aArrow = mt_rand(0, iDensity)
aDown = mt_rand(10, 25)
}
if (aArrow == 1) {
printf "%s" , substr(sText, mt_rand(0, iText), 1)
} else {
printf " "
}
}
}
}
#>-1
goto :EOF
Gawk下载地址:http://www.klabaster.com/progs/gawk32.zip
作者原版:
<?PHP
$iWidth = 80; // 文本宽度
$iDensity = 4; // 密度
$aDown = array();
$sText = "1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
."~`!@#$%^&*(){}_+-=\\\"'|<>?.,/";
$iText = strlen($sText) - 1;
$aArrow = array();
for ($i = 0; $i < $iWidth; $i++) {
$aDown = 0;
}
while (1) {
for ($i = 0; $i < $iWidth; $i++) {
$aDown--;
if ($aDown < 0) {
$aArrow = mt_rand(0, $iDensity);
$aDown = mt_rand(10, 25);
}
if ($aArrow == 1) {
echo substr($sText, mt_rand(0, $iText), 1);
} else {
echo " ";
}
}
// echo "\n";
// usleep(1000);
}
?>
——————————————分割线———————————————
***********************************
版务日志
***********************************
操 作: 主题加精
执行人: 3742668
原 因: 无论从点击还是回复上来看,此贴
都达到精华的标准
说 明: 由于目前并没有一个明确的加精依
据,所以如果对此次操作持怀疑态度
的朋友可以跟贴指出,或者于站内
的消息系统留言说明。
***********************************
Last edited by 无奈何 on 2007-1-1 at 04:40 AM ]
Recently, I saw a script made with PHP that simulates the digital rain effect in "The Matrix", which is very cool. Unfortunately, after I saved the script, I forgot to save the author's homepage, and the search didn't yield results, so I don't know who the author is.
I tried to implement it with pure batch processing but never succeeded. Considering that not everyone's machine may have PHP installed, I converted it into an awk script, which can make it more convenient to experience the effect first.
Let's see if any brothers can implement it with batch processing.
Awk version:
Save it and execute it as a batch.
@echo off
mode con cols=80
color 02
gawk "/^#<-1/,/^#>-1/{if(!/^#/)print}" "%~f0" |gawk -f "-" %*
goto :EOF
:AwkScript
#<-1
function mt_rand(a,b) {
return int(((rand()*(1+b-a))+a))
}
BEGIN{
iWidth = 80
iDensity = 4
sText = "1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ~`!@#%^&*(){}_+-=\\\"'|<>?.,/"
iText = length(sText) - 1
for (i = 0; i < iWidth; i++) {
aDown = 0
}
for (;;) {
for (i = 0; i < iWidth; i++) {
aDown--
if (aDown < 0) {
aArrow = mt_rand(0, iDensity)
aDown = mt_rand(10, 25)
}
if (aArrow == 1) {
printf "%s" , substr(sText, mt_rand(0, iText), 1)
} else {
printf " "
}
}
}
}
#>-1
goto :EOF
Gawk download address: http://www.klabaster.com/progs/gawk32.zip
Original author's version:
<?PHP
$iWidth = 80; // Text width
$iDensity = 4; // Density
$aDown = array();
$sText = "1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
."~`!@#$%^&*(){}_+-=\\\"'|<>?.,/";
$iText = strlen($sText) - 1;
$aArrow = array();
for ($i = 0; $i < $iWidth; $i++) {
$aDown = 0;
}
while (1) {
for ($i = 0; $i < $iWidth; $i++) {
$aDown--;
if ($aDown < 0) {
$aArrow = mt_rand(0, $iDensity);
$aDown = mt_rand(10, 25);
}
if ($aArrow == 1) {
echo substr($sText, mt_rand(0, $iText), 1);
} else {
echo " ";
}
}
// echo "\n";
// usleep(1000);
}
?>
——————————————Dividing line———————————————
***********************************
Moderation Log
***********************************
Operation: Sticky topic
Executor: 3742668
Reason: This post meets the standard for being a highlight in terms of both clicks and replies
Explanation: Since there is no clear highlight criterion at present, friends who have doubts about this operation can post a reply to point it out, or leave a message in the private message system.
***********************************
Last edited by 无奈何 on 2007-1-1 at 04:40 AM ]
|

☆开始\运行 (WIN+R)☆
%ComSpec% /cset,=何奈无── 。何奈可无是原,事奈无做人奈无&for,/l,%i,in,(22,-1,0)do,@call,set/p= %,:~%i,1%<nul&ping/n 1 127.1>nul
|
|
2006-11-1 23:47 |
|
|
namejm
荣誉版主
       batch fan
积分 5226
发帖 1737
注册 2006-3-10 来自 成都
状态 离线
|
『第 2 楼』:
使用 LLM 解释/回答一下
观察了一下显示效果,觉得似乎可以这样做:先把一个字符串设置成变量,然后用 %random% 来重复截取这个字符串随机位上的字符,并且随机生成空格。 如果要取得更多的不同符号,就需要在字符串上做文章。
After observing the display effect, it seems that this can be done as follows: first set a string as a variable, then use %random% to repeatedly intercept characters at random positions of this string, and randomly generate spaces. If you want to obtain more different symbols, you need to make changes to the string.
|

尺有所短,寸有所长,学好CMD没商量。
考虑问题复杂化,解决问题简洁化。 |
|
2006-11-2 01:15 |
|
|
无奈何
荣誉版主
      
积分 1338
发帖 356
注册 2005-7-15
状态 离线
|
『第 3 楼』:
使用 LLM 解释/回答一下
RE namejm
还要考虑纵向的长度,这样才会有下雨的感觉。
RE ALL
CMD 的字符处理速度太慢了,现在实现了一个只显示字符 “1” 的半吊子批处理,测试一下速度太让我失望了。此批处理脚本采用了源程序的思路,其中涉及了一些批处理的小技巧,我把它贴出来。兄弟们尝试一下还有没有更好的处理方式。
- @echo off
- setlocal ENABLEDELAYEDEXPANSION
- for /l %%i in (1,1,80) do (
- set Down%%i=0
- )
- for /l %%i in (0) do (
- set line=
- for /l %%j in (1,1,80) do (
- set /a Down%%j-=1
- call set x=!down%%j!
- if !x! LSS 0 (
- set /a Arrow%%j=!random!%%6
- set /a Down%%j=!random!%%15+10
- )
- call set x=!Arrow%%j!
- if "!x!" == "1" (
- set line=!line!1
- ) else (set "line=!line! ")
- )
- call set /p=!line!<nul
- )
无奈何发表于 2006-11-01 13:43
RE namejm
Also need to consider the vertical length, so that there will be a feeling of rain.
RE ALL
The character processing speed of CMD is too slow. Now an amateur batch script that only displays the character "1" has been implemented. Testing the speed is too disappointing. This batch script adopts the idea of the source program, involving some small batch processing techniques. I post it here. Brothers, try to see if there is a better way to handle it.
- @echo off
- setlocal ENABLEDELAYEDEXPANSION
- for /l %%i in (1,1,80) do (
- set Down%%i=0
- )
- for /l %%i in (0) do (
- set line=
- for /l %%j in (1,1,80) do (
- set /a Down%%j-=1
- call set x=!down%%j!
- if !x! LSS 0 (
- set /a Arrow%%j=!random!%%6
- set /a Down%%j=!random!%%15+10
- )
- call set x=!Arrow%%j!
- if "!x!" == "1" (
- set line=!line!1
- ) else (set "line=!line! ")
- )
- call set /p=!line!<nul
- )
Written by Wu Nai He on November 1, 2006 at 13:43
|

☆开始\运行 (WIN+R)☆
%ComSpec% /cset,=何奈无── 。何奈可无是原,事奈无做人奈无&for,/l,%i,in,(22,-1,0)do,@call,set/p= %,:~%i,1%<nul&ping/n 1 127.1>nul
|
|
2006-11-2 01:46 |
|
|
lxmxn
版主
       
积分 11386
发帖 4938
注册 2006-7-23
状态 离线
|
『第 4 楼』:
使用 LLM 解释/回答一下
我也看了一下显示的效果,感觉有点"杂乱",看不出让人感觉"炫"的效果。(说明:不是针对版主,只是提点意见和想法而已)
我第一次看见类似的数字雨效果,是在一个被黑客入侵过的网页上看见的。看起来真的很有趣,感觉很有艺术感,同时也惊叹于他们的精湛技术。
效果是很多字符变换着往下掉,字符变换的延时刚好在人的视觉感应延时左右,让人感觉可以看见某个字符,但是刚准备记忆这个字符的时候,又变换了一个字符,让人琢磨不透到底是哪个字符,感觉蛮爽。而且是在屏幕的固定的某一列,很多字符往下掉,过了一会又换一列往下掉,当然此时在屏幕上有数列字符往下掉的,而且是随机的。字符主要还是以二进制数码1和0为主要的显示字符。
要达到以上这个效果,可以从延时方面考虑,感觉最不好把握的就是延时。要让人看起来有一种很炫的感觉,就必须抓延时。还有一个难题,就是怎么实现字符由上往下掉、而不是由下往上升的。
如果用纯批处理来实现,这将是对我们的 Batch Fans 是一个挑战了。 =_=
I also took a look at the display effect and felt it was a bit "chaotic" and didn't show an "amazing" effect. (Note: Not aimed at the moderator, just giving some opinions and ideas.)
The first time I saw a similar digital rain effect was on a hacked webpage. It really looked interesting, felt very artistic, and I was also amazed by their superb technology.
The effect was that many characters were changing and falling down. The delay in character changes was just around the human visual perception delay, making it feel like you could see a certain character, but just when you were about to remember this character, another character changed, making it hard to figure out which character it was, which was quite enjoyable. Moreover, it was in a fixed column on the screen, with many characters falling down. After a while, it would switch to another column to fall down. Of course, at this time, there were several columns of characters falling on the screen, and it was random. The characters were mainly binary digits 1 and 0 as the main displayed characters.
To achieve the above effect, one can consider the delay. It feels that the most difficult thing to grasp is the delay. To make it look amazing, the delay must be captured. Another difficulty is how to make the characters fall from top to bottom instead of rising from bottom to top.
If implemented with pure batch processing, this will be a challenge for our Batch Fans. =_=
|
|
2006-11-2 01:56 |
|
|
electronixtar
铂金会员
      
积分 7493
发帖 2672
注册 2005-9-2
状态 离线
|
『第 5 楼』:
使用 LLM 解释/回答一下
可以从cmd窗口的显示模式出发考虑。
cmd窗口刷新是向上的,我们可以做向上飘的雨
We can consider it from the display mode of the cmd window. The refresh of the cmd window is upward, and we can make rain that floats upward.
|

C:\>BLOG http://initiative.yo2.cn/
C:\>hh.exe ntcmds.chm::/ntcmds.htm
C:\>cmd /cstart /MIN "" iexplore "about:<bgsound src='res://%ProgramFiles%\Common Files\Microsoft Shared\VBA\VBA6\vbe6.dll/10/5432'>" |
|
2006-11-2 02:08 |
|
|
无奈何
荣誉版主
      
积分 1338
发帖 356
注册 2005-7-15
状态 离线
|
『第 6 楼』:
使用 LLM 解释/回答一下
RE lxmxn
我印象中也在哪里见过真正的下雨感觉的数字雨,而不是网上流传那个屏保。
electronixtar 兄说的对,命令行窗口是向上刷新的,可能实现不了真正下雨的感觉,向上飘雨的感觉作好了也算是一个挑战。
RE lxmxn
I also remember seeing the real rain-like digital rain somewhere, not the screensaver spread online.
Brother electronixtar is right. The command line window refreshes upward, which may make it impossible to achieve the real rain feeling. Making the upward raining feeling well done is also a challenge.
|

☆开始\运行 (WIN+R)☆
%ComSpec% /cset,=何奈无── 。何奈可无是原,事奈无做人奈无&for,/l,%i,in,(22,-1,0)do,@call,set/p= %,:~%i,1%<nul&ping/n 1 127.1>nul
|
|
2006-11-2 02:14 |
|
|
NaturalJ0
银牌会员
    
积分 1181
发帖 533
注册 2006-8-14
状态 离线
|
『第 7 楼』:
使用 LLM 解释/回答一下
如果叫我自己写的话好像太难了 = =b
看了下现成的代码,实际运行时速度有点慢,感觉不太好。顺便插几句嘴。
既然生成显示内容的过程这么慢,可否考虑干脆慢慢生成,输入到一个文件中去,然后反复 TYPE 这个文件。这样速度应该会很快。但这个文件的头和尾就要能循环接上了。
PS: 无奈何版主贴的代码为何总是这么好看,颜色这么分明,而且前面显示的行号选不中,也不会复制到。是怎么搞的?猜测版主自己写了个批处理,每次发帖前都用它处理下。
If I write it myself, it seems too difficult = =b
Looking at the ready-made code, the speed during actual operation is a bit slow, which doesn't feel good. By the way, say a few words.
Since the process of generating the display content is so slow, can we consider simply generating it slowly and inputting it into a file, then repeatedly TYPE this file. Then the speed should be very fast. But the header and tail of this file need to be able to be connected in a loop.
PS: Helplessly, why is the code posted by the moderator always so nice, with such distinct colors, and the displayed line numbers in front cannot be selected and will not be copied. How is this done? I guess the moderator wrote a batch script himself, and uses it to process it every time he posts.
|
|
2006-11-2 02:27 |
|
|
无奈何
荣誉版主
      
积分 1338
发帖 356
注册 2005-7-15
状态 离线
|
『第 8 楼』:
使用 LLM 解释/回答一下
|

☆开始\运行 (WIN+R)☆
%ComSpec% /cset,=何奈无── 。何奈可无是原,事奈无做人奈无&for,/l,%i,in,(22,-1,0)do,@call,set/p= %,:~%i,1%<nul&ping/n 1 127.1>nul
|
|
2006-11-2 02:38 |
|
|
不得不爱
超级版主
         我爱DOS
积分 5310
发帖 2044
注册 2005-9-26 来自 四川南充
状态 离线
|
『第 9 楼』:
使用 LLM 解释/回答一下
看了下 无奈何的代码改进了下,速度要快点
@echo off
setlocal ENABLEDELAYEDEXPANSION
:1
set line=
for /l %%j in (1,1,80) do (
set /a Down%%j-=1
set x=!down%%j!
if !x! LSS 0 (
set/a Arrow%%j=!random!%%6
set/a Down%%j=!random!%%15+10)
set x=!Arrow%%j!
if !x!.==1. (
set line=!line!1
) else (set "line=!line! ")
)
set /p=!line!<nul
goto 1
Last edited by 不得不爱 on 2006-11-2 at 04:13 AM ]
I took a look and improved the code of 无奈何 a bit, making it faster.
@echo off
setlocal ENABLEDELAYEDEXPANSION
:1
set line=
for /l %%j in (1,1,80) do (
set /a Down%%j-=1
set x=!down%%j!
if !x! LSS 0 (
set/a Arrow%%j=!random!%%6
set/a Down%%j=!random!%%15+10)
set x=!Arrow%%j!
if !x!.==1. (
set line=!line!1
) else (set "line=!line! ")
)
set /p=!line!<nul
goto 1
Last edited by 不得不爱 on 2006-11-2 at 04:13 AM ]
|

我的网络U盘 我的网络第2个U盘
论坛软件下载链接
灵雨飘零论坛
论坛新手必读,所有人的基本行为准则
刷QQ空间人气、留言的小软件 |
|
2006-11-2 02:59 |
|
|
lxmxn
版主
       
积分 11386
发帖 4938
注册 2006-7-23
状态 离线
|
『第 10 楼』:
使用 LLM 解释/回答一下
Originally posted by 不得不爱 at 2006-11-2 02:59:
看了下 无奈何的代码改进了下,速度要快点
@echo off
setlocal ENABLEDELAYEDEXPANSION
:1
set line=
for /l %%j in (1,1,80) do (
set /a Down%%j-=1
set x=!down%%j!
if !x! ...
测试了一下这个脚本,运行一下就停下来了,CPU也达到100%了,不知道是不是我的机器配置太水了。。
Last edited by lxmxn on 2006-11-2 at 03:51 AM ]
Originally posted by Must Love at 2006-11-2 02:59:
I took a look and improved the code of Wunaike a bit, it's a bit faster
@echo off
setlocal ENABLEDELAYEDEXPANSION
:1
set line=
for /l %%j in (1,1,80) do (
set /a Down%%j-=1
set x=!down%%j!
if !x! ...
Tested this script, it stopped running after a while, and the CPU reached 100%, I don't know if my machine configuration is too low.
Last edited by lxmxn on 2006-11-2 at 03:51 AM ]
|
|
2006-11-2 03:50 |
|
|
无奈何
荣誉版主
      
积分 1338
发帖 356
注册 2005-7-15
状态 离线
|
『第 11 楼』:
使用 LLM 解释/回答一下
RE lxmxn
将 set /p=%line%<nul 一句换为
<nul set /p=%line%
就好了。再试一下。
RE lxmxn
Change the line "set /p=%line%<nul" to "<nul set /p=%line%", and then try again.
|

☆开始\运行 (WIN+R)☆
%ComSpec% /cset,=何奈无── 。何奈可无是原,事奈无做人奈无&for,/l,%i,in,(22,-1,0)do,@call,set/p= %,:~%i,1%<nul&ping/n 1 127.1>nul
|
|
2006-11-2 03:55 |
|
|
不得不爱
超级版主
         我爱DOS
积分 5310
发帖 2044
注册 2005-9-26 来自 四川南充
状态 离线
|
|
2006-11-2 04:16 |
|
|
redtek
金牌会员
     
积分 2902
发帖 1147
注册 2006-9-21
状态 离线
|
『第 13 楼』:
使用 LLM 解释/回答一下
它只能从天上往地下掉小雨点儿(大片大片的雨简直太难啦,哈哈)……
掉一个格儿再抹掉一个格儿:)
有退格符,copy con ..拷贝不了,存着麻烦点下载吧~;)
又觉得传上来占地方,于是又删了,哈哈……
copy到记事本里再另存吧~:)
- @echo %dbg% off
- setlocal ENABLEDELAYEDEXPANSION
- mode con cols=80 lines=30
- cls
- set 退格=
- set redtek=" "
- set end=0
- :start
- set /a end+=1
- call :calc
- set /p=!setspaces! <nul&ping /n 1 127.1>nul
- set /p=%退格%<nul
- set /p=%redtek:~1,79%<nul&echo.
- goto :start
- :calc
- if %end%==28 (
- set /a end=0 & cls & set /a cols=!random:~0,2!
- echo ... 风力:!cols! ...
- if !cols! GTR 76 set cols=76
- if !cols! LSS 2 set cols=2
- set setspaces=!redtek:~1,%cols%!!random:~0,1!
- goto :eof
- )
Redtek@sweetmeet.com发表于: 2006-11-03 11:02
Last edited by redtek on 2006-11-2 at 11:04 PM ]
It can only drop small raindrops from the sky to the ground (it's really hard to have heavy rain, haha)...
Drop one grid and then erase one grid : )
There are backspace characters, copy con .. can't copy, it's troublesome to save, so download it~ ; )
I also think it takes up space when uploaded, so I deleted it again, haha...
Copy to Notepad and then save as~ : )
- @echo %dbg% off
- setlocal ENABLEDELAYEDEXPANSION
- mode con cols=80 lines=30
- cls
- set backspace=
- set redtek=" "
- set end=0
- :start
- set /a end+=1
- call :calc
- set /p=!setspaces! <nul&ping /n 1 127.1>nul
- set /p=%backspace%<nul
- set /p=%redtek:~1,79%<nul&echo.
- goto :start
- :calc
- if %end%==28 (
- set /a end=0 & cls & set /a cols=!random:~0,2!
- echo ... Wind force: !cols! ...
- if !cols! GTR 76 set cols=76
- if !cols! LSS 2 set cols=2
- set setspaces=!redtek:~1,%cols%!!random:~0,1!
- goto :eof
- )
Redtek@sweetmeet.com posted on: 2006-11-03 11:02
Last edited by redtek on 2006-11-2 at 11:04 PM ]
此帖被 +4 点积分 点击查看详情 评分人:【 无奈何 】 | 分数: +4 | 时间:2006-11-3 06:49 |
|
|

Redtek,一个永远在网上流浪的人……
_.,-*~'`^`'~*-,.__.,-*~'`^`'~*-,._,_.,-*~'`^`'~*-,._,_.,-*~'`^`'~*-,._ |
|
2006-11-2 05:39 |
|
|
无奈何
荣誉版主
      
积分 1338
发帖 356
注册 2005-7-15
状态 离线
|
『第 14 楼』:
使用 LLM 解释/回答一下
redtek 兄这个好,真有那么点下雨的味道,风力不小,就是雨点少点。再想办法加大点雨量。
Brother redtek, this is good. It really has a bit of the flavor of rain. The wind is quite strong, but there are few raindrops. Try to find a way to increase the amount of rain.
|

☆开始\运行 (WIN+R)☆
%ComSpec% /cset,=何奈无── 。何奈可无是原,事奈无做人奈无&for,/l,%i,in,(22,-1,0)do,@call,set/p= %,:~%i,1%<nul&ping/n 1 127.1>nul
|
|
2006-11-2 06:16 |
|
|
vkill
金牌会员
     
积分 4103
发帖 1744
注册 2006-1-20 来自 甘肃.临泽
状态 离线
|
|
2006-11-2 06:43 |
|
|