Skip to content

Instantly share code, notes, and snippets.

@abul4fia
abul4fia / 00Example.md
Last active July 26, 2024 18:45
Landscape barchart for manim

Landscape barchart for manim

Example code

from manim import *
from landscapebarchart import LandscapeBarChart

# Note that the y axis in this landscape bar chart will be horizontal, and the x_axis will be vertical
# Also when the documentation/code refers to bar heights, it will be actually the rectangle width,
@abul4fia
abul4fia / Transforms.md
Last active June 27, 2024 20:16
Manim's transforms
Transform(a,b) ReplacementTransform(a,b) TransformFromCopy(a,b)
a initial shape a a a
a final shape b b a (never changed)
b initial shape b b a (temporarly)
b final shape b (never changed) b (never changed) b
In scene during transform a (morphing into b) a (morphing into b) b (morphing from a's shape)
In scene after transform a (in the shape of b) b b

See illustrative video here -> https://gist.github.com/assets/44573666/71b711f1-88ab-4065-8aa9-a8c333ffaa29

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

@abul4fia
abul4fia / 00_Orthogonal connections.md
Last active July 27, 2024 10:58
Orthogonal connections

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