Skip to content

Instantly share code, notes, and snippets.

View uwezi's full-sized avatar

Uwe Zimmermann uwezi

View GitHub Profile
@uwezi
uwezi / 20260124_benzene.py
Last active January 24, 2026 13:35
[animated chemistry] Using special animations on chemical formulae. #manim #chemistry #transformbyglyphmap #chemfig #animation #tikz
from MF_Tools import TransformByGlyphMap
class benzeneAnim(Scene):
def construct(self):
mol1 = Tex(
r"\chemfig{*6(-=-=-=)}",
tex_template=myChemTemplate
).set_stroke(width=3)
mol2 = Tex(
r"\chemfig{*6(--=-(=O)-=)}",
tex_template=myChemTemplate
@uwezi
uwezi / 20260124_chemfig.py
Last active January 24, 2026 12:55
[Organic chemistry] Using LaTeX's chemfig macro in Manim. #manim #latex #tikz #chemfig #chemistry
from manim import *
from mol2chemfigPy3 import mol2chemfig
myChemTemplate = TexTemplate(
tex_compiler="latex",
output_format='.dvi',
preamble=r"""
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{chemfig}
@uwezi
uwezi / 20260121_longdiv.py
Last active January 20, 2026 23:20
[long division] Long division in Manim. #manim #math #animation
class longdiv(Scene):
def construct(self):
# https://www.calculatorsoup.com/calculators/math/longdivision.php
divisor = 123
dividend = 764556
divisor_mobj = VGroup(
*Tex(f"{divisor}")[0]
)
remainder = 0
divisor_mobj.arrange_in_grid(
@uwezi
uwezi / 20260112_smiley.py
Last active January 12, 2026 13:03
[Smileys in equations] Use smiley characters in LaTeX equations in Manim. #manim #latex #smiley #pdf
class smileyeqn(Scene):
def construct(self):
smiley = ImageMobject("bilder/slightly-smiling-face_1f642.png")
tex_templ = TexTemplate()
tex_templ.add_to_preamble(r"\DeclareMathOperator{\sinc}{sinc}")
eqn = MathTex(r"\sinc(x) = \frac{\sin(x)}{x}", tex_template=tex_templ).to_edge(UP)
self.add(eqn)
eqn2 = eqn.copy().next_to(eqn,DOWN)
smiley.scale_to_fit_width(eqn2[0][5].width*1.5)
smileys = Group(
@uwezi
uwezi / 20260110_linear.py
Last active January 10, 2026 18:15
[smooth transition] Smooth transition between two linear functions. #manim #math #line
# https://math.stackexchange.com/questions/2493537/smooth-transition-between-linear-functions
class oscdot4(Scene):
def construct(self):
def f1(x):
return 0 + 0.5*x*2*PI
def f2(x):
return f1(3) + 2.5*(x-3)*2*PI
x0 = 2
@uwezi
uwezi / 20251214_spherehole.scad
Last active January 10, 2026 12:56
[Import .stl mesh] Import an .stl file as a mesh into Manim. #manim #3D #stl #mesh
$fn=60;
difference()
{
sphere(r=1.5);
cylinder(h=4,r=1,center=true);
}
@uwezi
uwezi / 20251220_mathtex.py
Last active December 20, 2025 16:13
[big expression] Finding and manipulating parts of a large LaTeX expression in LaTeX. #manim #mathtex #latex #indexlabels
from MF_Tools import ir
class bigeqn(Scene):
def construct(self):
eqn = MathTex(
r"""1+\sum_{i=1}^{2}\left\lfloor\left(
\frac{1}{\sum\limits_{j=1}^{i}\left\lfloor\left(\cos\left(\frac{(j-1)!\,+1}{j}\pi\right)^2\right)\right\rfloor}
\right)^\frac{1}{1}\right\rfloor"""
)
# uncomment for index labels
#self.add(eqn, index_labels(eqn[0]).set_color(RED))
@uwezi
uwezi / 20251211_newton.py
Last active January 22, 2026 15:24
[planetary orbit] Simulating a stable planetary orbit in Manim. #manim #astro #physics #updater #newton
class orbit(Scene):
def construct(self):
ax = Axes(
x_range=[-200e9,200e9,50e9],
y_range=[-200e9,200e9,50e9],
x_length=8,
y_length=8,
tips=False
)
G = 6.67e-11
@uwezi
uwezi / 20251210_glow.py
Last active December 10, 2025 18:48
[Glow effect] Adding a blurry copy of an object. #manim #glow #shadow #PIL #bitmap
from PIL import Image, ImageFilter
class Scene2(MovingCameraScene):
def construct(self):
def blur_image(mobjs, blur=15, bright=1.2, scale_first=1.2):
scene = Scene()
render = scene.renderer
objs = VGroup(*[m.copy().scale(scale_first, about_point=m.get_center()) for m in mobjs])
render.camera.set_pixel_array(np.zeros_like(render.camera.pixel_array))
render.camera.capture_mobjects(objs)
@uwezi
uwezi / 20251025_tikz.py
Last active October 27, 2025 16:16
[Tikz and XeLaTeX] Rednering Tikz code using XeLaTeX in Manim. #manim #latex #xelatex #dvisvgm #tikz
from manim import *
class tikztest(Scene):
def construct(self):
MyTexTemplate = TexTemplate(
tex_compiler="xelatex",
output_format=".xdv",
documentclass=r"\documentclass[preview,dvisvgm]{standalone}"
)
MyTexTemplate.add_to_preamble(r"\usepackage{tikz}")