Skip to content

Instantly share code, notes, and snippets.

@abul4fia
abul4fia / 00README.md
Last active April 14, 2024 11:18
Code utilities

Code utilities

The module code_utils.py contains functions useful to deal with code.

Currently it only contains find_in_code() function, described below

find_in_code(code, string, lines)

Finds all occurrences of the string string in the code object code, optionally restricting the search to the lines specified in the lines

@abul4fia
abul4fia / Animations.md
Created March 11, 2024 08:56
How Animation works (more or less)

How animations work (more or less)

To be frank, I don't know all the details about making your own custom Animation class. I know only a general idea, but the details are fuzzy. I usually end up using a trial-and-error approach trying different methods and reading the source code of similar animations, until it works. But the main idea is:

  1. An animation receives a mobject (it can be a group) on which it will operate. In the __init__ method usually it only stores that object into self.mobject, so every animation has that object, and other animation attributes such as the run time, rate function, etc.
  2. When used in a .play(), manim will call its begin() method. Usually you don't need to override that. The default implementation creates another inner object called self.starting_mobject which stores the initial state of the mobject being animated, and it is simply a deep copy of self.mobject (although you can override how that starting mobject is created by overriding `create_starting_mobj
@abul4fia
abul4fia / 00README.md
Last active March 5, 2024 08:21
New LatexTip for latex-style arrows

LatexTip

Manim provides few styles of arrow tips, basically a filled triangle and the "stealth".

This python module implements Latex-style arrow tips. The shape is a perfect copy of the one used by Computer Modern fonts. It was produced by exporting to svg a latex document containing $\to$, and editing the resulting SVG using Inkscape to remove the arrow stem and leave only the tip. This SVG was read into manim to extract the array of points used to define this class.

This is an example of several arrows with several kinds of tips pointing in all directions (the code is the file example.py in this gist.

OrthogonalConnection

The class OrthogonalConnection creates a polyline that goes from p1 to p2, composed only by horizontal and vertical segments. The shape of the line is controlled by the path parameter.

There are two ways to use this class:

  1. p1 and p2 are the start and end points of the line, and path is a string with the characters "-" and "|" indicating the horizontal and vertical segments of the line.

    For example "-|-" will start with a horizontal segment, that will go until the x coordinate intermediate between p1 and p2, then a vertical segment up to the y coordinate of p2, and finally a horizontal segment to p2.

@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.

@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 / journal_navigation_links.py
Created August 29, 2023 17:41
Process logseq journals to include navigation links
@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 / ligth_theme.py
Last active November 13, 2023 18:50
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 / 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")