Settings

Theme

Show HN: Matrix rain, Conway's Game of Life and Mandelbrot set for terminals

github.com

158 points by akinomyoga 6 years ago · 39 comments

Reader

anderspitman 6 years ago

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/

Tagbert 6 years ago

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 6 years ago

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

  • Tagbert 6 years ago

    “Charter” = “Character” Phone typos

GeertJohan 6 years ago

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

Zhyl 6 years ago

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

tylerneylon 6 years ago

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

laretluval 6 years ago

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

  • stallmanite 6 years ago

    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 6 years ago

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 6 years ago

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, }},
  • akinomyogaOP 6 years ago

    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.

  • superkuh 6 years ago

    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 6 years ago

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

      • fhars 6 years ago

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

        • saagarjha 6 years ago

          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…

  • KhoomeiK 6 years ago

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

  • WantonQuantum 6 years ago

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

    brew install gawk

    make clean

    make

meanmrmustard92 6 years ago

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 6 years ago

    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);
  • akinomyogaOP 6 years ago

    Please just wait for several minutes.

mark_l_watson 6 years ago

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.

Mashimo 6 years ago

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

Maybe because I run through WSL?

  • akinomyogaOP 6 years ago

    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.

    • akinomyogaOP 6 years ago

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

  • tyingq 6 years ago

    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.

    • hoov 6 years ago

      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.

      • tyingq 6 years ago

        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?

      • craftinator 6 years ago

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

  • bnjms 6 years ago

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

WantonQuantum 6 years ago

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

willis936 6 years ago

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

rolandog 6 years ago

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

Keyboard Shortcuts

j
Next item
k
Previous item
o / Enter
Open selected item
?
Show this help
Esc
Close modal / clear selection