A Halloween Trick XOR Treat: Crafting Educational Animations with Manim

A seemingly simple Halloween-themed meme, saved years ago by a chemistry teacher from Japan on Twitter, has inspired a unique project that blends educational content creation with the spirit of the holiday. This creative endeavor, undertaken by NSHipster, showcases the power of the open-source animation software Manim, originally developed by Grant Sanderson for his highly popular 3Blue1Brown YouTube channel. The project culminates in a short, animated video that cleverly illustrates the concept of the XOR (exclusive OR) logical operation, demonstrating how complex mathematical and programming concepts can be made accessible and engaging through visual storytelling.
The genesis of this Halloween animation traces back to a tweet by Twitter user @38mo1, a chemistry teacher based in Japan. The tweet, a Halloween-themed Boolean logic meme, resonated with the author of the NSHipster piece, prompting its archival for a yearly dose of seasonal amusement. This seemingly minor personal anecdote serves as a poignant reminder of how inspiration can strike from unexpected corners, often leading to more significant creative outputs.
The journey from a saved meme to a fully produced animation took a significant leap when the author sought to teach his children advanced "snake maths," a venture that, while described as a "long story," pointed towards an interest in complex mathematical visualization. This led to the discovery of Manim, the open-source software underpinning the visually stunning educational videos produced by 3Blue1Brown. The realization that this powerful tool was publicly available opened the door for NSHipster to embark on its own animated exploration.
The core of the NSHipster project is a demonstration of Manim’s capabilities, particularly its application in creating educational explainer videos. The resulting "Trick XOR Treat" video is not merely a seasonal novelty but a testament to the software’s flexibility and power in visualizing abstract concepts. The project also makes its source code publicly available on GitHub, embodying the spirit of open-source collaboration and encouraging others to explore the possibilities of Manim.
The Genesis of Manim: From Hackathon to Educational Powerhouse
The story of Manim is intrinsically linked to Grant Sanderson, the creator of the 3Blue1Brown YouTube channel. Back in 2015, at a hackathon, Sanderson conceived of "very scrappy code for visualizing functions as transformations." This initial, playful experiment, driven by a desire to hone his Python skills, laid the groundwork for what would evolve into Manim. Today, the 3Blue1Brown channel boasts over 6.5 million subscribers, a testament to the effectiveness of Sanderson’s approach to making complex mathematical ideas understandable and captivating. Manim, as the engine behind these visualizations, has become an indispensable tool for educators and content creators alike.
Navigating Manim’s Installation: Challenges and Solutions
Manim, while powerful, has historically carried a reputation for being challenging to install. This perception stems from several factors. Firstly, the software caters to a broad audience, including individuals who may not identify as programmers. Secondly, the inherent complexities of working with motion graphics contribute to the installation hurdles. Lastly, its Python foundation, while offering flexibility, can introduce dependencies that complicate the setup process for some users.
However, the development landscape for Manim has seen significant improvements, and modern approaches offer streamlined installation pathways. One robust solution is the utilization of Docker. Docker, a platform designed for containerization, excels at packaging applications with their system dependencies, effectively circumventing many of the common installation issues. For those seeking an immediate and stable environment to run Manim, the Docker approach is presented as a pragmatic option:
$ docker run --rm -it -v "/full/path/to/your/directory:/manim" manimcommunity/manim manim -qm scene.py MySceneName
This command allows users to run Manim within a containerized environment, ensuring a consistent and isolated setup without directly interfering with the host system’s configurations. The command mounts a local directory into the container, enabling users to manage their Manim projects seamlessly.
Despite the efficiency of Docker, the author of the NSHipster piece advocates for a more integrated approach, emphasizing the long-term benefits of establishing a proper Python development environment. This perspective suggests that while Docker provides a quick entry point, a native installation allows for deeper engagement with the tool and a more profound understanding of its ecosystem. The article then proceeds to outline an "opinionated setup guide for Manim on macOS in 2025," aiming to demystify the installation process for a wider audience.
An Opinionated Setup Guide for Manim on macOS (2025)
The setup guide begins with essential preparatory steps, often referred to as mise en place in culinary contexts, highlighting the methodical nature of the process.
- Install
mise: This versatile tool manager simplifies the handling of various programming language versions and their associated tools.# Install mise $ brew install mise - Install Python and
uv:uvis a fast, Python-based package installer and dependency manager, designed to be a modern alternative to pip and poetry.# Install Python and uv $ mise use -g python@latest uv@latestThis command instructs
miseto globally install the latest versions of Python anduv.
Following these initial installations, the guide moves to project creation:
# Create a new project
$ uv init my-explainer
$ cd my-explainer
# Now open with your preferred $EDITOR
The uv init command sets up a new project directory with the necessary configuration files for uv, facilitating the management of project-specific dependencies.
Next, the guide addresses Manim’s system dependencies, crucial for its rendering capabilities:
# Install Manim dependencies
$ brew install pkg-config cairo # for graphics
$ brew install --cask mactex-no-gui # for LaTeX
$ brew install sox # for voiceovers
These commands leverage Homebrew, a popular package manager for macOS, to install essential libraries for graphics rendering (cairo, pkg-config), LaTeX typesetting (mactex-no-gui), and audio processing (sox). The inclusion of LaTeX is particularly important for Manim as it relies on it for rendering high-quality text and mathematical equations.
A crucial step in verifying the setup is a health check:
# Is everything working? (👍)
$ uv run manim checkhealth
This command, executed within the project’s virtual environment managed by uv, runs Manim’s built-in health check utility. A successful execution, indicated by a positive emoji, confirms that all dependencies are correctly installed and configured, paving the way for animation creation.
Setting the Scene: Crafting the "Trick XOR Treat" Animation
The Manim API is characterized by its extensive documentation and a rich collection of examples, providing a solid foundation for users. The NSHipster project’s "Trick XOR Treat" scene serves as a concrete illustration of how to leverage this API.
The Python code for the scene is structured within a TrickXORTreat class, inheriting from Manim’s Scene class. The construct method orchestrates the animation sequence. The animation begins by defining a rounded rectangle to serve as a panel background, upon which a title, "Trick XOR Treat," is displayed.
The core of the visualization involves two circles, representing sets in a Venn diagram. Manim’s Difference and Intersection objects are instrumental in creating the shapes required for an XOR operation. For XOR, the area where the circles overlap (the intersection) is excluded, while the areas unique to each circle are included. This is achieved by creating Difference objects for the parts of each circle that do not intersect with the other, and a Difference object for the intersection that is then effectively made transparent or excluded.
To visually represent the "trick" aspect of the Halloween theme, simple faces are rendered within the unique sections of the circles. These faces consist of basic circles for eyes and a parametric function defining a sinusoidal curve for the mouth. This demonstrates Manim’s ability to render more complex graphical elements beyond basic shapes.
The animation sequence is meticulously defined using Manim’s animation methods:
FadeInandWrite: These are used to introduce the panel background and the title, respectively, withFadeInemploying a scaling effect for a more dynamic entrance.Create: The two circles are drawn sequentially using theCreateanimation, followed by brief pauses to allow the viewer to process the visual information..animate.set_fill: This method is employed to dramatically fill the unique sections of the circles with orange, representing the "true" outcomes of the XOR operation. Thesmoothrate function ensures a fluid and visually appealing transition.FadeInwithshiftandscale: The faces are introduced with a slight upward shift and scaling, adding a playful and characterful element to the animation.
The Manim API’s procedural nature is highlighted as a refreshing departure from declarative frameworks. The process involves explicitly creating objects, positioning them, and then instructing them on how to animate. This imperative programming style, while requiring explicit control, offers a direct and intuitive way to build complex visual sequences.
The Development Loop: Previewing and Rendering
To streamline the animation development process, the example project includes specialized mise tasks for previewing and rendering.
mise run preview: This command renders the scene at a lower resolution (480p) and frame rate (15 fps). The output is then automatically opened in QuickTime Player, facilitating rapid iteration and feedback during the animation creation process. This low-fidelity preview is crucial for quickly testing animations without the significant time investment required for full-resolution rendering.mise run render: Once the animation is finalized, this command is used to produce the high-quality, final output. This is the command for generating videos intended for sharing.
The result of a successful render command is a polished animation that can be shared, akin to the example video presented at the beginning of the NSHipster article.
Adding Voice: AI Narration with Manim Voiceover
A hallmark of the 3Blue1Brown explainer videos is the distinctive narration by Grant Sanderson. For this Halloween project, however, an AI-powered approach to voiceover was adopted. The manim-voiceover library, with a specific mention of a slightly temperamental "fixed" version due to compatibility issues with newer Python versions and ElevenLabs’ v3 models, integrates text-to-speech services.
The integration involves modifying the scene class to inherit from VoiceoverScene and configuring a speech service, in this case, ElevenLabs. The example code demonstrates how to specify a voice (Liam) and a model (eleven_v3), with a workaround for a known issue related to transcription models.
The with self.voiceover(...) context manager is a key feature. It allows developers to embed narration directly within the animation script. Crucially, the self.wait() call within this context manager automatically synchronizes with the duration of the generated audio, eliminating the need for manual timing adjustments. This significantly simplifies the post-production process, allowing for a cohesive audio-visual experience to be rendered directly from Manim.
The first-time execution of code utilizing manim-voiceover prompts the user for an ElevenLabs API token, which can be obtained from their account dashboard. This token is then typically stored in an .env file, ensuring secure and convenient access for subsequent runs.
Broader Implications: Sparking Curiosity Through Accessible Education
The NSHipster "Trick XOR Treat" project, rooted in a simple meme and amplified by the power of Manim, embodies the core philosophy of effective educational content: sparking curiosity, delighting the audience, and making complex ideas approachable. The original inspiration from the 3Blue1Brown channel highlights the profound impact that well-crafted visual explanations can have on learning.
By making the project open-source, NSHipster not only shares its creation but also invites a broader community to engage with Manim and the principles of educational animation. This Halloween project serves as a timely reminder that complex topics, whether Boolean logic or advanced mathematics, can be demystified and made enjoyable through creative visualization. The accessibility of tools like Manim empowers individuals, from educators to hobbyists, to transform abstract concepts into engaging visual narratives, fostering a deeper understanding and a greater appreciation for the subjects they explore. The "costume" of being a math YouTuber, as the article suggests, is indeed open-source, and for those who embrace it, it offers a "pretty good look" at the intersection of education, technology, and creative expression.






