Hacker News new | past | comments | ask | show | jobs | submit login
Show HN: Matrix rain, Conway's Game of Life and Mandelbrot set for terminals (github.com/akinomyoga)
158 points by akinomyoga on March 7, 2020 | hide | past | favorite | 39 comments



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

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

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

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


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


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. :)


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


“Charter” = “Character” Phone typos


A long time ago I wrote 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 :)


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-...)? I could only find unofficial one https://www.youtube.com/watch?v=mUXFxSmZMis (maybe I can add a link to this unofficial one)


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


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

https://gist.github.com/tylerneylon/e70a684b88809f74168f3a36...

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


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


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.


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.


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, }},


Thank you. This issue is discussed here https://github.com/akinomyoga/cxxmatrix/issues/3

It is caused by the UTF-8 unaware awk. I haven't yet figured out why it happens, but at least you need to set your locale to one of UTF-8 locales.


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.


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


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


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…


I was able to fix it by find all 'ï' and replace with '\U000000EF' in glyph.inl


I fixed this on my mac (High Sierra) with:

brew install gawk

make clean

make


And shortly after, I did this:

brew cask install iterm2


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.


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);


Please just wait for several minutes.


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.


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


Thanks, that is what I tried to say: better on ITerm.


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

Maybe because I run through WSL?


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.


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... 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++.


The default WSL terminal is slow. I always install an X server. VcXsrv works great, with good Windows clipboard support. Then you can use urxvt or some other Linux terminal that's faster.


I've tried a bunch of X servers, but with a 4k display, they're all too slow to be usable. I'm settling for running WSL inside Alacritty for now.


I use VcXsrv in the multiwindow mode where it uses the Windows 10 window manager for each X app, instead of being fullscreen. Is that also slow on a 4k screen?


Lol, the downfall of high powered output hardware. It then requires equally high powered input hardware. Solving this problem is my life now.


Are you running the new Windows Terminal (Preview)? If not, and you try it, is it any better?


That made it even worse.


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


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


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




Join us for AI Startup School this June 16-17 in San Francisco!

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: