
Show HN: Matrix rain, Conway's Game of Life and Mandelbrot set for terminals - akinomyoga
https://github.com/akinomyoga/cxxmatrix
======
anderspitman
Great work! This is one of the best rain implementations I've seen.

A while back I implemented[0] a (pretty basic) Matrix rain in JavaScript that
will pull your latest public GitHub contributions and use that for the rain
text. Demo here[1]. And of course my useless Game of Life icons, golicaons[2]
(demo [3]).

[0]:
[https://github.com/anderspitman/redpill](https://github.com/anderspitman/redpill)

[1]:
[https://anderspitman.net/apps/redpill/](https://anderspitman.net/apps/redpill/)

[2]:
[https://github.com/anderspitman/golicons](https://github.com/anderspitman/golicons)

[3]:
[https://anderspitman.net/apps/golicons/](https://anderspitman.net/apps/golicons/)

~~~
pluc
There is a screensaver that does Matrix rain with GitHub's latest public
commits: [https://github.com/winterbe/github-matrix-
screensaver](https://github.com/winterbe/github-matrix-screensaver)

------
Tagbert
Back in the 80s when most people were using DOS text screens, we would
sometime play a joke on a friend/coworker. We would get on their computer and
run a small terminate-and-stay-resident (background process) program called
rain.com. It would sit in the background while they ran their word processor
or spreadsheet. After some time, it would cause one character to “fall” down
the screen. They would see it happen and not know what was going on. Then it
would make another charter fall. By then, the person would usually call out to
someone else to come and look at this weird thing. But then the program would
up the rate and start dropping multiple charters. It kept increasing the rate
and eventually all of the characters on their screen had rained down and were
in a pile on the bottom of the screen. At that point, we would press some key
combination and their original screen would appear. That is usually when we
would let them in on the joke and reboot their machine to remove the TSR Rain.

People didn’t lock their computers back then. :)

~~~
samplatt
Huh. I've seen that before but always thought it was a virus (back when some
viruses were harmless fun).

------
GeertJohan
A long time ago I wrote gomatrix:
[https://github.com/GeertJohan/gomatrix](https://github.com/GeertJohan/gomatrix)

It's a Matrix emulator inspired by cmatrix. It doesnt have as many features as
this posts one (e.g. just 2 colors for the kanas), but was a fun exercise to
learn Go. Pull requests welcome :)

~~~
akinomyoga
Thank you for your comment. Do you have some screenshots, animated GIFs or
videos of gomatrix which I can link from cxxmatrix README
([https://github.com/akinomyoga/cxxmatrix#the-matrix-rains-
in-...](https://github.com/akinomyoga/cxxmatrix#the-matrix-rains-in-
terminals))? I could only find unofficial one
[https://www.youtube.com/watch?v=mUXFxSmZMis](https://www.youtube.com/watch?v=mUXFxSmZMis)
(maybe I can add a link to this unofficial one)

------
Zhyl
As a fan of terminals, matrix rain, Conway's game of life and Mandelbrot sets,
this is relevant to my interests.

------
tylerneylon
I few years ago I put together a basic Mandelbrot terminal animation:

[https://gist.github.com/tylerneylon/e70a684b88809f74168f3a36...](https://gist.github.com/tylerneylon/e70a684b88809f74168f3a3618fd98a4)

It runs nicely in Python 2 (and slower in Python 3).

Here's a nice code golf Mandelbrot that also uses no image library (it
produces a bmp file):
[https://codegolf.stackexchange.com/a/23465](https://codegolf.stackexchange.com/a/23465)

------
laretluval
Once everyone is working from home it is going to be prime time for terminal-
based yak shaving.

~~~
stallmanite
Along those lines but from a more general angle I bet tons of other really
useful things get done that maybe wouldn’t have otherwise.

------
rs23296008n1
I like the speed and dynamic aspects. Use of 256 colours means extra shades
etc. Simple effect and very good.

Now I want to dust off my old snake game and upgrade it to 3D.

------
saagarjha
Oh boy, neither GCC nor Clang liked the Unicode one bit:

    
    
      $ make 2>&1 | head
      c++ -std=c++17 -Wall -Wextra -Os -MD -MP -MF cxxmatrix.dep -c -o cxxmatrix.o cxxmatrix.cpp
      In file included from cxxmatrix.cpp:595:
      glyph.inl:78:2: error: converting to execution character set: Invalid argument
         78 | {U'�', 21, {127, 65, 65, 65, 65, 65, 127, }},
            |  ^~~~
      glyph.inl:79:2: error: converting to execution character set: Invalid argument
         79 | {U'�', 21, {573695, 2072768, 104616, 104344, 37000, 1609860, 430211, }},
            |  ^~~~
      glyph.inl:80:2: error: converting to execution character set: Invalid argument
         80 | {U'�', 21, {164354, 260859, 2015779, 1221155, 692770, 429602, 1238014, }},

~~~
superkuh
You made it further than I did. The majority of machines out there today
probably do not support the required -std=c++17. I know none of my OS installs
(and their compilers) do.

~~~
saagarjha
I think Xcode has shipped with a compliant C++17 compiler for over a year, but
I used GCC to compile this one :)

~~~
fhars
GCC has supported this for more than a year, too (at least since 7.4.0).

~~~
saagarjha
GCC 7.4.0 sadly misses certain C++ features (filesystems) and does not
correctly support others (template argument deduction). I'm waiting for 20.04
to hopefully bump GCC to something newer…

------
meanmrmustard92
This is fantastic. What arguments should I pass ./cxxmatrix to get the
mandelbrot set or game of life? Can't seem to get it to work / couldn't figure
it out from the repo.

~~~
justinhj
I've been playing around with the code, you can just comment out the bits you
don't want to run in the main function...

    
    
      // buff.s1number();
      // for (int i = 1; i < argc; i++)
      //  buff.s2banner(argv[i]);
      // buff.s3rain(2800, buffer::s3rain_scroll_func_tanh);
      buff.s4conway();
      // buff.s5mandel();
    
      // Infinite rain
      //buff.s3rain(0, buffer::s3rain_scroll_func_const);

------
mark_l_watson
So very cool. I just built and installed it on my MacBook. Looks great on
Apple's standard terminal, and I think a little bit better even on ITerm 2.

~~~
saagarjha
Interestingly, it was exceedingly laggy on Terminal.app for me. iTerm
seemingly handled it better.

~~~
mark_l_watson
Thanks, that is what I _tried_ to say: better on ITerm.

------
Mashimo
Those terminal matrix rain animations are always super slow for me at higher
resolution. Using two cores 100%.

Maybe because I run through WSL?

~~~
akinomyoga
Thank you for your comment. I'm not sure for your specific case, but generally
the performance largely depends on the terminal emulators in my experience.
For example, xterm and Windows ConPTY are super slow which are sometimes 100
times slower than the fastest terminals. urxvt (rxvt-unicode), alacritty,
terminology are usually fast. xfce4-terminal, qterminal, mintty are
acceptable. VTE based terminals (GNOME terminal, lxterminal, etc.), termit,
etc. are slow in my environments.

~~~
akinomyoga
Actually one of the reason why I wrote this program is to test the terminal
performances. When I'm searching the benchmark data of Alacritty, I found this
issue
[https://github.com/alacritty/alacritty/issues/289#issue-2001...](https://github.com/alacritty/alacritty/issues/289#issue-200130020)
where the existing Matrix rain program "cmatrix" is mentioned. I tried
"cmatrix" in my terminal (I'm using a terminal which I wrote from scratch for
myself) and found that the Matrix rain of "cmatrix" is cheaper than I
expected. That is the reason why I wrote "cxxmatrix", a version with
additional optical effects written in C++.

------
WantonQuantum
Runs noticeably faster for me if I change -Os to -Ofast

------
willis936
Needed to run make twice but it’s running on a raspberry pi 4 + raspbin
stable.

------
rolandog
This is so cool! Thank you for the great effort.

