From the lab

ASCII Pattern Generator

We decided to explore the world of ASCII animations and how to create visually appealing patterns with the help of audio and video inputs.

Press to view video


We found our inspiration from an artist who posted ASCII animations on Instagram. Combining art with programming was an intriguing challenge and something we thought would provide us with a bunch of valuable learnings on the way. Since we already wanted to do something in Python, we decided to fully focus on the artistic capabilities of the programming language.

The Process

During our project, we focused on conducting research and expanding our knowledge of how to use Python for artistic purposes and how to send ASCII characters between terminals. To achieve this, we dedicated a significant portion of our project to exploring, gathering information, and exchanging best practices and ideas.

In pursuit of knowledge, we encountered several valuable resources to utilize during the project. These included a video-to-ASCII converter Python package, which we sourced from GitHub, a cross-platform colored terminal text library from PyPI, and a real-time video-to-ASCII converter also from GitHub.

Our major challenge was optimizing our Python program to handle large arrays and complex image and video effects. In addition, to make it react to real audio, our ultimate goal was to run the program at a speedy 30 frames per second, adding to the task's complexity. We understood that utilizing advanced matrix math techniques was necessary to achieve the level of performance we were looking for. A knowledge we possessed but had to dig up from the place of the brain where it was hidden away since school.

Sending frames in real-time across devices with web sockets was another challenge, as we, as mentioned, needed to send significant arrays between ourselves. We used compression and low-latency unpacking of the compressed frames to overcome this issue.

Result / Key takeaways

Our final product is an interactive terminal player that streams and reproduces generated ASCII patterns between two terminals. Utilizing our Python program, a microphone, or even a mouse click can create an animation with ASCII characters that are sent from one terminal to another. For those who remember the iconic WinAmp visualizations, it's like a blast from the past!

Throughout our project journey, we learned valuable lessons that will help us in future endeavors:

  • The WebSocket protocol is not as complex as it may seem and can be a valuable tool for creating interactive web applications.
  • We realized that optimizing frame structures is crucial for building real-time animations and had to develop our own image format to ensure that different effects would fit our ASCII player. This taught us the importance of good architecture and planning to avoid getting lost in the details and creating a total mess (as Omar freely expressed it).

Looking ahead to a potential next iteration of the project, we would add new and exciting ASCII effects and additional ways to interact with the player. The possibilities are endless, or actually, exactly 128 characters and 256 colors since that's how many ASCII characters and colors there are to use in the terminal.

Animering med ASCII-tecken