New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

matrix-rain

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

matrix-rain

Matrix Rain effect in cli. Characters from a file can also be used.

  • 1.1.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

Matrix Rain in terminal with node

Installation

npm install -g matrix-rain

Usage

matrix-rain --help
Usage: matrix-rain opts? filePath?
opts: --direction=v|h = change direction. If reading from file direction is h (horizontal)
filePath: Read characters from file and set direction=h
By default generate random ascii chars in v (vertical) direction

Screenshots

Vertical Matrix

Horizontal Matrix

Story Time

On christmas eve I watched the The Matrix (1999) and was inspired by the matrix effect. I was curious to see if I could replicate this effect without using other node modules.

There's blessed and node-ncurses which would have helped but rather than using the library I wanted to learn how console cursor manipulation works behind the scenes. I browsed through the source code of colors.js and got a few pointers. Thank you github.

I've been programming for 6 years full time but on that day I discovered terminal escape codes. I googled around and found VT100 ANSI codes table

I disovered process.stdout has a columns and rows property. It also fires a resize even when console is resized. With escape codes I can clear the screen, move the cursor to any position in the screen, change colors and do really cool things which previously I thought was vodoo magic. There's even support for 8 bit colors in console. Whoah! All I have to do is write the appropriate escape code sequence in stdout and that is it.

oh my god!

I learned a couple of things

  • Its faster if I flush commands to stdout when I have finished rendering a frame rather than doing it immediately
  • Writing utf-8 is slower than ascii. I tried random kanji characters but it was about twice as slow. Not sure why.
  • Rather than clearing entire screen and drawing the everything again, its much faster to only modify parts of screen that have changed.

Initial algorithm somewhat worked. I wondered what else I could do. I used a trick to change swap numRows and numCols and I could render the matrix horizontally. Rather than generate random ascii characters, what if I could read characters from a file.

This had an interesting side effect that it was a great visualization of the source code. It looked like the computer was programming itself in parallel. I changed the code so it uses jquery.js and voila! I was reading snippets of jquery source code. While I took my dog for a run, I left it running. My wife (non-technical) sent me a message "Hey your computer is in the matrix, its really cool!". Younger noj would be very impressed of older noj.

The source code matrixRain.coffee is < 200 lines of code.

Keywords

FAQs

Package last updated on 06 Feb 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc