Not long ago I started to work with Rust and for me it is amazing. The speed, the type safety, the number of use cases are just amazing in Rust.
As practice, I wanted to implement the Matrix code rain, which I always wanted to implement but never got there. It turned out to be a good little project. It includes algorithms and terminal manipulation.
My github repo: Matrix Rainfall
There are 3 different structs which represent each element:
Symbol: Here we store and edit each character of the matrix. The function of setting a random symbol is implemented here (it will be called in the Column). The fading function is also implemented here. For the color manipulation, I used a third-party crate.
Column: Here we initialize each symbol, and most of the algorithm (starting raindrops, space between raindrops, calling random characters, calling fade function) happens here. We store here each vector (raindrop) start point and end point.
Matrix: Practically, it represents a table where you have the terminal width and height. The setting of the background color, moving the cursor, and the initialization of the columns happen here.
With parameters, we can set the speed, the color of the background, and the color of the characters.
So far it works well with '1' and '0' characters but if I want to add more then the columns don't hold themselfs, like this:
I hope somebody can help me with this
Reference:
repo
Top comments (0)