前段时间小编在刷抖音的时候看到很多人用bat制作黑客帝国的数字雨,比如:
bat代码
【想要学习Python。加小编Python学习群:813542856,即可免费领取一整套系统的板Python学习教程!】
<pre style="-webkit-tap-highlight-color: transparent; box-sizing: border-box; font-family: Consolas, Menlo, Courier, monospace; font-size: 16px; white-space: pre-wrap; position: relative; line-height: 1.5; color: rgb(153, 153, 153); margin: 1em 0px; padding: 12px 10px; background: rgb(244, 245, 246); border: 1px solid rgb(232, 232, 232); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">@echo off
title 黑客帝国
setlocal ENABLEDELAYEDEXPANSION
color 0a
for /l %%i in (1,1,80) do (
set Down%%i=0
)
:loop
for /l %%j in (1,1,80) do (
set /a Down%%j-=1
if !down%%j! LSS 0 (
set /a Arrow%%j=!random!%%4
set /a Down%%j=!random!%%15+10
)
if "!Arrow%%j!" == "1" (
set /a chr=!random!%%2
set /p=!chr!<nul
) else (
set /p= <nul
)
)
goto loop
goto :eof
</pre>
那么如何用Python制作黑客帝国的代码雨呢?
安装
采用Python包管理工具pip安装即可:
<pre style="-webkit-tap-highlight-color: transparent; box-sizing: border-box; font-family: Consolas, Menlo, Courier, monospace; font-size: 16px; white-space: pre-wrap; position: relative; line-height: 1.5; color: rgb(153, 153, 153); margin: 1em 0px; padding: 12px 10px; background: rgb(244, 245, 246); border: 1px solid rgb(232, 232, 232); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">pip install git+https://github.com/will8211/unimatrix.git
</pre>
运行
安装好以后在终端运行下面命令即可:
<pre style="-webkit-tap-highlight-color: transparent; box-sizing: border-box; font-family: Consolas, Menlo, Courier, monospace; font-size: 16px; white-space: pre-wrap; position: relative; line-height: 1.5; color: rgb(153, 153, 153); margin: 1em 0px; padding: 12px 10px; background: rgb(244, 245, 246); border: 1px solid rgb(232, 232, 232); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">unimatrix -n -s 96 -l o
unimatrix -c blue -u ILovePython
unimatrix -c yellow -l e
</pre>
命令参数
<pre style="-webkit-tap-highlight-color: transparent; box-sizing: border-box; font-family: Consolas, Menlo, Courier, monospace; font-size: 16px; white-space: pre-wrap; position: relative; line-height: 1.5; color: rgb(153, 153, 153); margin: 1em 0px; padding: 12px 10px; background: rgb(244, 245, 246); border: 1px solid rgb(232, 232, 232); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">USAGE
unimatrix [-a] [-b] [-c COLOR] [-f] [-g COLOR] [-h] [-l CHARACTER_LIST] [-n]
[-o] [-s SPEED] [-u CUSTOM_CHARACTERS]
OPTIONAL ARGUMENTS
-a Asynchronous scroll. Lines will move at varied speeds.
-b Use only bold characters
-c COLOR One of: green (default), red, blue, white, yellow, cyan,
magenta, black
-f Enable "flashers," characters that continuously change.
-g COLOR Background color (See -c). Defaults to keeping
terminal's current background.
-h Show this help message and exit
-l CHARACTER_LIST Select character set(s) using a string over letter
codes (see CHARACTER SETS below.)
-n Do not use bold characters (overrides -b)
-o Disable on-screen status
-s SPEED Integer up to 100. 0 uses a one-second delay before
refreshing, 100 uses none. Use negative numbers for
even lower speeds. Default=85
-t TIME Exit the process after TIME seconds
-u CUSTOM_CHARACTERS Your own string of characters to display. Enclose in
single quotes ('') to escape special characters. For
example: -u '#%^&*()_+[]{}|;':",./<>?" )
u Custom characters selected using -u switch
For example: '-l naAS' or '--character_list=naAS' will give something similar
to the output of the original cmatrix program in its default mode.
'-l ACG' will use all the upper-case character sets. Use the same
letter multiple times to increase the frequency of the character set. For
example, the default setting is equal to '-l knnssss'.
- With most modern Linux terminals (gnome-terminal, konsole, lxterminal,
xfce4-terminal, mate-terminal) simply having the font installed system-wide
is enough. The terminal will fall back to it for the Klingon, meaning that
you don't have to select it in your terminal settings. 'Horta' seems not to
work in Konsole. Fonts may need to be set manually as fallbacks in
.Xresources for older terminals, such as urxvt and xterm.
KEYBOARD CONTROL
SPACE, CTRL-c or q exit
- or LEFT decrease speed by 1
- or RIGHT increase speed by 1
[ or DOWN decrease speed by 10
] or UP increase speed by 10
a toggle asynchronous scrolling
b cycle through bold character options
(bold off-->bold on-->all bold)
f toggle flashing characters
o toggle on-screen status
1 to 9 set color: (1) Green (2) Red (3) Blue (4) White
(5) Yellow (6) Cyan (7) Magenta (8) Black
(9) Terminal default
! to ( set background color (same colors as above, but pressing
shift + number)
EXAMPLES
Mimic default output of cmatrix (no unicode characters, works in TTY):
unimatrix -B -u Linux -c blue
Use default character set, plus dollar symbol (note single quotes around
special character):
unimatrix -n -l ens -s 50</pre>
网友评论