Show HN: Rotating torus in terminal (but with kitty graphics protocol)

Hacker News Top Tools

Summary

A developer shares a rotating torus rendered in the terminal using the Kitty graphics protocol, explaining the base64 encoding and protocol details.

Hi HN,<p>I&#x27;m taking Computer Graphics @ Stanford this summer and wanted to express some very simple concepts I had in mind. That&#x27;s why I wrote a rotating torus in C. Going from writing a ray-tracer that works in Blender to pure C with no dependencies feels relaxing. Wanted to try Kitty Graphics Protocol on the way, rendering images in terminal felt cool.<p>Open to comments and suggestions.
Original Article
View Cached Full Text

Cached at: 08/08/26, 02:18 PM

# torus v0.5 Source: [https://andreadimatteo.com/torus-v0-5.html](https://andreadimatteo.com/torus-v0-5.html) ·2026\-08\-01 --- Hi, this is Andrea\. After playing a little bit with the torus programthat hasn't fallen into the oblivion for now, I decided to render it using the[Kitty Graphics Protocol](https://sw.kovidgoyal.net/kitty/graphics-protocol/)that also[my terminal](https://ghostty.org/)supports\. If you don't pay too much attentionlike me at first, you could think of sending raw pixel data encoded in plain ASCII\. Well, notoo easy hehe\. You must send base64 encoded images \(RGB, RGBA, PNG\)\. For those who don't know, the encoding \(included me before reading about it\) works in the following way: - takes 3 bytes as input - splits it into words of 6 bits each - given \`i\`, an 6 bits unsigned, return the char \`map\[i\]\` where \`map\` is an encoding specific map, do this for each of the four 6 bits unsigned - if the input isn't multiple of 3 bytes then it's padded with \`=\` \(special char\) as needed If you want to know more about itand you want to do it the old way, just read about it on the[RFC](https://datatracker.ietf.org/doc/html/rfc4648#section-4)\. It's deceptively simple to implement for RGB dataand you can flex that you know that RFC stands for Request For Comment\. Once you have your base64 encoded image, you can send it, in chunks of maximum 4096 bytes, using the kitty graphics protocol\. All the graphics follow the format`<ESC\>\_G<control data\>;<payload\><ESC\>\\`, which, translated in`printf\(\)`means:`printf\("\\033\_G<control data\>;<payload\>\\033\\\\"\);`, where`<control data\>`is a comma separated key value string that ends with`;`\. Some basic information for this map are: - display on terminal: \`a=T\` ~must specify, otherwise will not display anything :\)~ - type of data: \`f=24/32/100\` for RGB, RGBA and PNG respectively \(must specify\) - width: \`s=%n\` \(must specify\) - height: \`v=%n\` \(must specify\) - compression: \`o=z\` \(optional\) - terminal columns and rows: \`c=%d,r=%d\` \(optional\) - more \(if there will be chunks following\): \`m=%1\` Now, with a real image rendering I could finally see what was happeningin fact, some very strange things were happening, like cut in half torus, not consistent light, and it was much easier to visually debug and also add cool stuff like colors and a second light \(of a different color\)\. It would be interesting to write`Metal`code to speed all this thing up on Apple Silicon, might be interesting to learnor just to suffer; or also make it a rendering engine that can actually load OBJ meshesor again, forget about this project forever\. This is the result for now, cool right :\) ? The code can be found the following[repo](https://github.com/andimatteo/torus) ![torus](https://andreadimatteo.com/static/torus.gif) > the fps counter makes it even more profesionaleven though it's useless, because it sleeps not to go over 33\.33 \(0\.o\)fun fact: did you know that magenta \(blue \+ red\) isn't a real color? it doesn't really exist on the visible spectrum, our brain just makes it up :\)

Similar Articles

Ratty: A terminal emulator with inline 3D graphics

Lobsters Hottest

# Ratty — A GPU-rendered terminal emulator with inline 3D graphics 🐀🧀 Source: [https://ratty-term.org/](https://ratty-term.org/) © 2026 Ratty,[Orhun Parmaksız](https://github.com/orhun)

Show HN: An ASCII 3D Rendering Engine

Hacker News Top

GlyphCSS is a JavaScript library that renders textured 3D meshes in the DOM using ASCII characters, supporting various 3D formats and integrating with vanilla JS, React, and Vue.

Tsplat – Run Gaussian splatting in your terminal

Hacker News Top

Tsplat is a Rust-based CLI tool that renders 3D Gaussian Splatting scenes directly in the terminal using only the CPU, even over SSH. It supports Unicode half-blocks and graphics protocols, with controls for navigation and auto-orbit.

Show HN: Rotation via Double Reflection

Hacker News Top

An interactive visualization tool demonstrating how rotations can be constructed using double reflections, built while studying Geometric Algebra.