4 行代码重现《黑客帝国》特效

提到《黑客帝国》,字符雨可谓是让人印象深刻。 那种科技感爆棚的特效,你是否也想来一套?这个,可以有。最近,名叫 akinomyoga 的 GitHub 用户,便上传了这样一个项目。

4 行代码重现《黑客帝国》特效-LaokNas网络技术笔记

只要有终端、有 C++,几行代码就能启动!超级方便有木有?

C++ Matrix in terminal

I wrote a simple terminal program of Matrix digital rain. A part of the purpose of this program is to test the performance of terminal emulators. Another purpose is just for fun. Enjoy it with fast terminals (e.g., urxvt, alacritty, terminology, etc.)!

Features

  • Hankaku kana characters as in the original film
  • Ten levels of “green”s using terminal 256 color support
  • Twinkling effects by adding random brightness fluctuations
  • Diffused reflection effects by cell background colors

Scenes

By default, the following scenes will be visited in turn. If you want to see each scene, please see the help (cxxmatrix --help).

  1. Number falls
  2. Banner – Show command line arguments by shining characters
  3. “The Matrix” rain – Wikipedia
  4. Conway’s Game of Life – Wikipedia
  5. The Mandelbrot set – Wikipedia
  6. (End scene) “The Matrix” rain

如何再现数字雨? 效果如此震撼,实现起来会不会很复杂?体验很简单。

首先,还是老规矩 —— 介绍一下环境需求。

需要有 git、C++ 编译器、GNU Maker 和 GNU AWK; 系统支持 UTF-8; 支持 256 色和 UTF-8 的终端。

而后,仅仅需要下面 4 行代码就能启动!

$ git clone https://github.com/akinomyoga/cxxmatrix.git

$ cd cxxmatrix

$ make

$ ./cxxmatrix ‘The Matrix’ ‘Reloaded’

炫酷效果展示

akinomyoga 做这个项目,除了检测终端模拟的性能,还有就是觉得特别有意思。

除了我们上面看到的《黑客帝国》字符雨,比较基础的实现包括数字掉落、字符闪烁显示。

4 行代码重现《黑客帝国》特效-LaokNas网络技术笔记

但是,没有 C++ 怎么办?

不急,博主还非常好心的总结了许多类似的,用其他语言可以在终端实现的 GitHub 项目。

C 语言实现: https://github.com/abishekvashok/cmatrix

Python 3 实现: https://github.com/will8211/unimatrix

Go 语言实现: https://github.com/GeertJohan/gomatrix

嫌终端实现还是麻烦?那试试在浏览器吧。

HTML5 Canvas 实现: https://github.com/tidwall/digitalrain

CSS 3 实现: https://github.com/raphaklaus/matrix-fx

WebVR 实现: https://github.com/pazdera/matrix-vr

当然,还有需要其它实现的方法,可以去这个 GitHub 项目中了解更多。

传送门 GitHub 项目地址: https://github.com/akinomyoga/cxxmatrix

Dependencies

You’ll probably need a decent ncurses library to get this to work. On Windows, using mingw-w64-ncurses is recommended (PDCurses will also work, but it does not support colors or bold text).

Building and installing cmatrix

To install cmatrix, use either of the following methods from within the cmatrix directory.

Using configure (recommended for most linux/mingw users)

autoreconf -i  # skip if using released tarball
./configure
make
make install

Using CMake

Here we also show an out-of-source build in the sub directory “build”. (Doesn’t work on Windows, for now).

mkdir -p build
cd build
# to install to "/usr/local"
cmake ..
# or to install to "/usr"
#cmake -DCMAKE_INSTALL_PREFIX=/usr ..
make
make install
© 版权声明
THE END
喜欢就支持一下吧
点赞0 分享
评论 抢沙发
头像
欢迎您留下宝贵的见解!
提交
头像

昵称

取消
昵称表情代码图片