China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-06-20 10:38
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » [Recommendation][Challenge Idea] Use a script to simulate the digital rain from The Matrix DigestI View 27,135 Replies 67
Original Poster Posted 2006-11-01 23:47 ·  中国 浙江 宁波 鹏博士宽带
荣誉版主
★★★
Credits 1,338
Posts 356
Joined 2005-07-15 12:09
20-year member
UID 40733
Gender Male
Status Offline
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 ]
Recent Ratings for This Post ( 2 in total) Click for details
RaterScoreTime
redtek +2 2006-11-02 23:15
hxuan999 +1 2006-11-16 22:24
  ☆开始\运行 (WIN+R)☆
%ComSpec% /cset,=何奈无── 。何奈可无是原,事奈无做人奈无&for,/l,%i,in,(22,-1,0)do,@call,set/p= %,:~%i,1%<nul&ping/n 1 127.1>nul

Floor 2 Posted 2006-11-02 01:15 ·  中国 广东 佛山 广东睿江科技有限公司
荣誉版主
★★★★
batch fan
Credits 5,226
Posts 1,737
Joined 2006-03-10 00:38
20-year member
UID 51697
From 成都
Status Offline
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没商量。
考虑问题复杂化,解决问题简洁化。
Floor 3 Posted 2006-11-02 01:46 ·  中国 浙江 宁波 鹏博士宽带
荣誉版主
★★★
Credits 1,338
Posts 356
Joined 2005-07-15 12:09
20-year member
UID 40733
Gender Male
Status Offline
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.



  1. @echo off
  2. setlocal ENABLEDELAYEDEXPANSION
  3. for /l %%i in (1,1,80) do (
  4. set Down%%i=0
  5. )

  6. for /l %%i in (0) do (
  7. set line=
  8. for /l %%j in (1,1,80) do (
  9. set /a Down%%j-=1
  10. call set x=!down%%j!
  11. if !x! LSS 0 (
  12. set /a Arrow%%j=!random!%%6
  13. set /a Down%%j=!random!%%15+10
  14. )
  15. call set x=!Arrow%%j!
  16. if "!x!" == "1" (
  17. set line=!line!1
  18. ) else (set "line=!line! ")
  19. )
  20. call set /p=!line!<nul
  21. )
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

Floor 4 Posted 2006-11-02 01:56 ·  中国 湖北 武汉 电信
版主
★★★★★
Credits 11,386
Posts 4,938
Joined 2006-07-23 17:10
19-year member
UID 59080
Status Offline

  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. =_=
Floor 5 Posted 2006-11-02 02:08 ·  中国 四川 成都 教育网
铂金会员
★★★★
Credits 7,493
Posts 2,672
Joined 2005-09-02 00:00
20-year member
UID 42173
Gender Male
Status Offline
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'>"
Floor 6 Posted 2006-11-02 02:14 ·  中国 浙江 宁波 鹏博士宽带
荣誉版主
★★★
Credits 1,338
Posts 356
Joined 2005-07-15 12:09
20-year member
UID 40733
Gender Male
Status Offline
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

Floor 7 Posted 2006-11-02 02:27 ·  中国 江苏 苏州 电信
银牌会员
★★★
Credits 1,181
Posts 533
Joined 2006-08-14 12:54
19-year member
UID 60484
Status Offline
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.
Floor 8 Posted 2006-11-02 02:38 ·  中国 浙江 宁波 鹏博士宽带
荣誉版主
★★★
Credits 1,338
Posts 356
Joined 2005-07-15 12:09
20-year member
UID 40733
Gender Male
Status Offline
RE NaturalJ0
Take a look at this post.
Batch code post coloring script Batch2ubb (CMD & GAWK)
  ☆开始\运行 (WIN+R)☆
%ComSpec% /cset,=何奈无── 。何奈可无是原,事奈无做人奈无&for,/l,%i,in,(22,-1,0)do,@call,set/p= %,:~%i,1%<nul&ping/n 1 127.1>nul

Floor 9 Posted 2006-11-02 02:59 ·  中国 四川 南充 电信
超级版主
★★★★
我爱DOS
Credits 5,310
Posts 2,044
Joined 2005-09-26 12:00
20-year member
UID 42843
Gender Male
From 四川南充
Status Offline
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 ]
Floor 10 Posted 2006-11-02 03:50 ·  中国 湖北 武汉 电信
版主
★★★★★
Credits 11,386
Posts 4,938
Joined 2006-07-23 17:10
19-year member
UID 59080
Status Offline
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 ]
Floor 11 Posted 2006-11-02 03:55 ·  中国 浙江 宁波 鹏博士宽带
荣誉版主
★★★
Credits 1,338
Posts 356
Joined 2005-07-15 12:09
20-year member
UID 40733
Gender Male
Status Offline
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

Floor 12 Posted 2006-11-02 04:16 ·  中国 四川 南充 电信
超级版主
★★★★
我爱DOS
Credits 5,310
Posts 2,044
Joined 2005-09-26 12:00
20-year member
UID 42843
Gender Male
From 四川南充
Status Offline
Oh, dizzy. If you change set /p=%line%<nul to set /p=!line!<nul, there's no problem either. The code on floor 9 has been updated.
Floor 13 Posted 2006-11-02 05:39 ·  中国 北京 联通
金牌会员
★★★★
Credits 2,902
Posts 1,147
Joined 2006-09-21 12:00
19-year member
UID 63324
Gender Male
Status Offline
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~ : )



  1. @echo %dbg% off
  2. setlocal ENABLEDELAYEDEXPANSION
  3. mode con cols=80 lines=30
  4. cls

  5. set backspace=
  6. set redtek=" "

  7. set end=0
  8. :start
  9. set /a end+=1
  10. call :calc
  11. set /p=!setspaces! <nul&ping /n 1 127.1>nul
  12. set /p=%backspace%<nul
  13. set /p=%redtek:~1,79%<nul&echo.
  14. goto :start

  15. :calc
  16. if %end%==28 (
  17. set /a end=0 & cls & set /a cols=!random:~0,2!
  18. echo ... Wind force: !cols! ...
  19. if !cols! GTR 76 set cols=76
  20. if !cols! LSS 2 set cols=2
  21. set setspaces=!redtek:~1,%cols%!!random:~0,1!
  22. goto :eof
  23. )
Redtek@sweetmeet.com posted on: 2006-11-03 11:02


[ Last edited by redtek on 2006-11-2 at 11:04 PM ]
Recent Ratings for This Post ( 1 in total) Click for details
RaterScoreTime
无奈何 +4 2006-11-03 06:49
    Redtek,一个永远在网上流浪的人……

_.,-*~'`^`'~*-,.__.,-*~'`^`'~*-,._,_.,-*~'`^`'~*-,._,_.,-*~'`^`'~*-,._
Floor 14 Posted 2006-11-02 06:16 ·  中国 浙江 宁波 鹏博士宽带
荣誉版主
★★★
Credits 1,338
Posts 356
Joined 2005-07-15 12:09
20-year member
UID 40733
Gender Male
Status Offline
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

Floor 15 Posted 2006-11-02 06:43 ·  中国 甘肃 甘南藏族自治州 合作市 电信
金牌会员
★★★★
Credits 4,103
Posts 1,744
Joined 2006-01-20 13:00
20-year member
UID 49241
Gender Male
From 甘肃.临泽
Status Offline
Why is the CPU usage so high?
1 2 3 5 Next ›
Forum Jump: