中国DOS联盟论坛

China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --
Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
Guest | Log in | Register | Members | Search | China DOS Union
中国DOS联盟论坛
The time now is 2026-08-10 16:54
47,811 topics / 349,897 posts / today 0 new / 48,256 members
DOS批处理 & 脚本技术(批处理室) » [Recommendation][Challenge Idea] Use a script to simulate the digital rain from The Matrix
Printable Version  27,934 / 67
Floor1 无奈何 Posted 2006-11-01 23:47
荣誉版主 Posts 356 Credits 1,338
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.


Gawk download address: http://www.klabaster.com/progs/gawk32.zip

Original author's version:



——————————————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 ]
Floor2 namejm Posted 2006-11-02 01:15
荣誉版主 Posts 1,737 Credits 5,226 From 成都
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.
Floor3 无奈何 Posted 2006-11-02 01:46
荣誉版主 Posts 356 Credits 1,338
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
Floor4 lxmxn Posted 2006-11-02 01:56
版主 Posts 4,938 Credits 11,386

  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. =_=
Floor5 electronixtar Posted 2006-11-02 02:08
铂金会员 Posts 2,672 Credits 7,493
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.
Floor6 无奈何 Posted 2006-11-02 02:14
荣誉版主 Posts 356 Credits 1,338
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.
Floor7 NaturalJ0 Posted 2006-11-02 02:27
银牌会员 Posts 533 Credits 1,181
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.
Floor8 无奈何 Posted 2006-11-02 02:38
荣誉版主 Posts 356 Credits 1,338
RE NaturalJ0
Take a look at this post.
Batch code post coloring script Batch2ubb (CMD & GAWK)
Floor9 不得不爱 Posted 2006-11-02 02:59
超级版主 Posts 2,044 Credits 5,310 From 四川南充
I took a look and improved the code of 无奈何 a bit, making it faster.


[ Last edited by 不得不爱 on 2006-11-2 at 04:13 AM ]
Floor10 lxmxn Posted 2006-11-02 03:50
版主 Posts 4,938 Credits 11,386
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
Floor11 无奈何 Posted 2006-11-02 03:55
荣誉版主 Posts 356 Credits 1,338
RE lxmxn
Change the line "set /p=%line%<nul" to "<nul set /p=%line%", and then try again.
Floor12 不得不爱 Posted 2006-11-02 04:16
超级版主 Posts 2,044 Credits 5,310 From 四川南充
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.
Floor13 redtek Posted 2006-11-02 05:39
金牌会员 Posts 1,147 Credits 2,902
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 ]
Floor14 无奈何 Posted 2006-11-02 06:16
荣誉版主 Posts 356 Credits 1,338
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.
Floor15 vkill Posted 2006-11-02 06:43
金牌会员 Posts 1,744 Credits 4,103 From 甘肃.临泽
Why is the CPU usage so high?
1 2 3 45  Next
[ Contact the Union admin team - 中国DOS联盟 - Standard version ]
Sponsored by ifanr Inc | © 2001–2023