M4444 / TMatrix

Terminal based replica of the digital rain from The Matrix.
GNU General Public License v2.0
381 stars 14 forks source link

More Authentic Experience - Custom Font #26

Open bsodcat opened 3 years ago

bsodcat commented 3 years ago

Hey I stumbled upon this project after not being satisfied with the accuracy of cmatrix, I just got into linux and back into programming about 5 months ago and I would like to contribute some accurate aesthetic to this projects already extensible and simple code.

My first feature request would be to add a custom font file (to the default if at all possible) that is an exact font image of the one used in the movies. I recognize the amount of work this could be to handle, but in the next couple months I will try to be tackling it head on, making an accurate font image. If I run into any issues It might take a bit seeings how I’m not used to programming in anything but C++, but we will see how this goes.

Most if not all the characters are english/Japanese with mirrored versions every now and then and I feel as if this could be easily done, let me know if you have any ideas or any concerns, Sorry if this sounds a bit weird as this is my first time really using github.

M4444 commented 3 years ago

Hey, I like your enthusiasm towards authenticity :)

Thoughts about about this have flown around before. One approach in creating a new font could be to replace some Latin characters with the katakana characters. A more elegant approach would be the replace the actual katakana characters with their flipped (and modified) versions. To do this one would need to figure out where the characters go in the font file. Most people on Arch install ttf-mplus to get fonts for Japanese characters so it could be useful to take a look at their font file and how it deals with this.

As for the looks there is for example [this design] that looks pretty spot on. Replacing the Japanese characters with something like this would solve the font side of the problem.

Now for the (perhaps) technically harder problem. The terminal pulls the font from the system so we have two parts that are outside the application. A perfect solution would be that the program changes the terminal font, runs and then changes it back to the original one. I didn't explore this deeply so I don't know how tractable this problem is but any partial solution would be a great step. For example changing the whole system font for Japanese characters (perhaps on installation), or changing the font for the current terminal session without returning it to the original.

Cmatrix has an option for changing the font to something weird in tty so exploring that might also be useful.

MestreLion commented 3 years ago

I've banged on this a lot in one of my pet projects, RoguePC (and its sibling PyRogue. So let me share my strategies and solutions, maybe some might be useful in TMatrix:

matrix() {
    if ! [[ "$TERM" == "linux" ]]; then
        cmatrix -sbu8  # X11, virtual TTY. See my next post
        return
    fi
    local default=$(mktemp) && trap 'rm -f -- "$default"' RETURN
    setfont -O "$default" matrix.psf  # Backup current font, set matrix PSF font
    cmatrix -sbxu8                    # run cmatrix, -x signals that font has japanese glyphs
    setfont "$default"                # restore previous font
}
MestreLion commented 3 years ago

For virtual terminals under X11, such as xterm or gnome-terminal, you need:

For xterm:

For Gnome-Terminal:

M4444 commented 3 years ago

Oh, this is very useful, you obviously know a lot about terminals. I won't be using matrix.psf because it has some characters that don't appear in the Matrix and it's also missing characters that do, so it doesn't really fit the goal of this project. I will look more deeply into the things you suggested so thanks for sharing your experience! Might contact you if I get stuck somewhere ;)