Skip to content

Instantly share code, notes, and snippets.

@abul4fia
abul4fia / 00README.md
Last active May 6, 2024 20:23
Working with sections in manim

Working with sections in manim

Manim provides out of the box the possibility of marking parts of your scene as separate sections, by using self.next_section(). This will cause a separate video to be rendered for each section, and then all of them will be stitched together for the final result. The final result will be the same as if you hadn't used sections at all.

But the use of sections allows you to mark some of them with the parameter skip_animations=True, and in that case, that section will not be rendered. The code of the section will be run anyway (because it may be defining objects or variables needed in following sections), but for every self.play(), only the final frame will be computed (and not rendered). This ensures that, at the end of the section, all objects are at the same positions as if the animations were played, but skipping the actual rendering significantly reduces the time required to run the code.

In addition, the resulting video when skip_animations=True is used will be s

@abul4fia
abul4fia / fixed_fixing.py
Created June 20, 2023 07:32
How to fix objects and transforms in a manim 3D scene
# Context:
#
# Although ThreeDScene has the method `self.add_fixed_in_frame_mobjects()`
# it doesnt work as expected if you want to have transforms that happen
# in the frame coordinates, instead of in 3D coordinates
#
# See https://discord.com/channels/581738731934056449/1120217688728424549/1120217688728424549
#
# This fix fixes the fixed objects in a different way that works under transforms
@abul4fia
abul4fia / manim_textbox.py
Created June 26, 2023 18:26
Text box for manim
def create_textbox(string, width, height, text_color=BLACK, align=ORIGIN, color=BLUE, buff=0.2):
tex_align = {
tuple(UL): "\\raggedright",
tuple(LEFT): "\\raggedright",
tuple(DL): "\\raggedright",
tuple(UP): "\\centering",
tuple(ORIGIN): "\\centering",
tuple(DOWN): "\\centering",
tuple(UR): "\\raggedleft",
tuple(RIGHT): "\\raggedleft",
@abul4fia
abul4fia / README.md
Created July 5, 2023 11:03
Quine in manim

A "Quine" is a program that reproduces its own source code in the standard output when it is run.

There is a trivial way of doing so, such as:

with open("source.py") as f:
    print(f.read())

But this is considered cheating. The code should not read the source file.

@abul4fia
abul4fia / example.py
Last active April 30, 2024 12:07
Generic formula transformation under control
"""
This is an example which uses the "low-level" interface, specifying
the indexes or slices() that should be transformed one into
another.
"""
class Test(Scene):
def construct(self):
m1 = MathTex(r"\frac{x}{y} = \frac{a}{b}\times5")
self.add(m1)
m2 = MathTex(r"x\cdot b = y\cdot a\times5")
@abul4fia
abul4fia / ligth_theme.py
Last active May 15, 2024 18:13
Light theme for manim
# Put this file in the same folder than your manim script
# and start your script with:
#
# import light_theme
from manim import *
config.background_color = WHITE
# Those are objects which are WHITE by default
@abul4fia
abul4fia / latex_items.py
Last active August 2, 2023 09:07
Latex items environment
"""
This module implements class LatexItems which is useful as an alternative
to manim's BulletedList.
Unless BulletedList, LatexItems uses standard latex itemize environment to
typeset the text and the bullets. The width of the paragraphs can be customized
as well as the kind of environment (itemize, enumerate, or description)
"""
from manim import Tex, TexTemplate
@abul4fia
abul4fia / journal_navigation_links.py
Created August 29, 2023 17:41
Process logseq journals to include navigation links
@abul4fia
abul4fia / timeline_of_animations.py
Created October 27, 2023 07:59
Play animations in given timeline
from typing import Iterable
def play_timeline(scene, timeline):
"""
Plays a timeline of animations on a given scene.
Args:
scene (Scene): The scene to play the animations on.
timeline (dict): A dictionary where the keys are the times at which the animations should start,
and the values are the animations to play at that time. The values can be a single animation
@abul4fia
abul4fia / 00README.md
Last active March 7, 2024 13:14
Concise syntax for manim's ValueTrackers

Shortcuts for working with valuetrackers

  • Tired of typing v.get_value()?
    Type ~v instead thanks to this trick.

  • Tired of typing v.animate.set_value(n)?
    Type v@n instead thanks to this trick.