cmatrix 是一个在终端中模拟《黑客帝国》中“数字雨”效果的经典小工具。在 Linux 下,自定义 cmatrix 通常从以下几个层面入手:
系统自带的 cmatrix 通常功能有限,建议从源码编译:
# Debian / Ubuntu
sudo apt install build-essential ncurses-dev git
# CentOS / Rocky / Alma
sudo yum groupinstall "Development Tools"
sudo yum install ncurses-devel
git clone https://github.com/abishekvashok/cmatrix.git
cd cmatrix
./configure
make
sudo make install
安装后一般位于:
/usr/local/bin/cmatrix
cmatrix -C red
cmatrix -C green
cmatrix -C blue
cmatrix -C yellow
cmatrix -C cyan
cmatrix -C magenta
cmatrix -b
cmatrix -a
cmatrix -u 4 # 更新速度(1-10)
cmatrix -s # 屏保模式
cmatrix -x # 数字雨(原版风格)
编辑 cmatrix.c:
#define DEFAULT_CHAR_SET "abcdefghijklmnopqrstuvwxyz0123456789"
你可以改成:
#define DEFAULT_CHAR_SET "01"
或:
#define DEFAULT_CHAR_SET "アイウエオカキクケコ"
然后重新编译:
make && sudo make install
在 cmatrix.c 中查找颜色相关代码,例如:
#define COLOR_GREEN 2
你可以改成:
#define COLOR_GREEN 10 // 亮绿
如果你终端支持 256 色,可以:
init_color()init_pair() + COLOR_PAIR()示例(伪代码):
init_color(10, 0, 1000, 0); // RGB
init_pair(1, 10, COLOR_BLACK);
attron(COLOR_PAIR(1));
echo 'alias matrix="cmatrix -a -b -C cyan -u 3"' >> ~/.bashrc
source ~/.bashrc
gnome-terminalalacritty / kittycmatrix -s
如果你需要完全自定义效果,可以考虑:
| 工具 | 特点 |
|---|---|
unimatrix |
Python,支持颜色/字符 |
tty-matrix |
Rust,性能更好 |
| 自己写 ncurses 程序 | 完全可控 |
cmatrix -a -b -C green -u 2
或:
cmatrix -x -C cyan -u 1
如果你愿意,我可以:
你想做到哪一步?