Fundamentals 5 min read

How 120,000 Lines of Code Became a Dancing Cai Xukun Animation

A Bilibili creator named NyeJu generated 120,000 lines of compilable C++ code that, through precise color‑coded patterns, animates a singing, dancing, rap‑performing version of Cai Xukun, detailing the workflow from theme selection to frame‑by‑frame color mapping and automated code generation.

Liangxu Linux
Liangxu Linux
Liangxu Linux
How 120,000 Lines of Code Became a Dancing Cai Xukun Animation

A Bilibili uploader known as NyeJu created a video where a character resembling the pop star Cai Xukun sings, dances, and raps, and the entire animation is produced from 120,000 lines of compilable C++ code.

The trick is not simple ASCII art or console color tricks; it relies on the code editor’s syntax‑highlighting mechanism. By placing correctly‑formatted code at specific positions, the editor displays the desired colors, which are then captured as video frames.

The workflow consists of several steps:

Choose a color theme (e.g., “Code Blue”) and map each programming keyword to a specific color.

Split the target video into individual frames, sample the pixel colors of each frame, and match each pixel to the nearest keyword color, recording a (color, length) pair.

Generate source code from the recorded pairs. This involves two sub‑steps:

Define a set of pattern s, such as using “pink, red, white” to represent declarations and “gray, transparent” for comments.

Match each (color, length) pair against the patterns and translate it into the corresponding code snippet.

Because a code fragment is generated for every video frame, the final animation runs smoothly. The project took roughly a week to complete; the massive codebase was produced automatically, not typed manually.

Although the showcased source is C++, NyeJu mentioned that the generation script itself is written in Python. The generated C++ code obeys normal syntax rules—keywords like const and static can be stacked arbitrarily, and identifiers or string literals may be of any length—ensuring that the code compiles without errors and that the editor’s syntax highlighting remains stable.

“The idea was inspired by a recent video from ‘He Tongxue’ titled ‘I made an animation with ten thousand lines of notes.’ I wanted to push it further.”

Overall, the project demonstrates how automated code generation combined with editor color mapping can turn a massive, yet syntactically valid, codebase into a visually compelling animation.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

animationCode GenerationPythonC++creative coding
Liangxu Linux
Written by

Liangxu Linux

Liangxu, a self‑taught IT professional now working as a Linux development engineer at a Fortune 500 multinational, shares extensive Linux knowledge—fundamentals, applications, tools, plus Git, databases, Raspberry Pi, etc. (Reply “Linux” to receive essential resources.)

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.