Skip to content

Instantly share code, notes, and snippets.

@uwezi
Last active January 24, 2026 13:35
Show Gist options
  • Select an option

  • Save uwezi/40d40158b5aef1a7378787712be1979e to your computer and use it in GitHub Desktop.

Select an option

Save uwezi/40d40158b5aef1a7378787712be1979e to your computer and use it in GitHub Desktop.
[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
).set_stroke(width=3)
mol2.shift(mol1.get_bottom()-mol2.get_bottom())
self.play(Create(mol1))
self.wait()
self.play(
TransformByGlyphMap(
mol1, mol2,
([0,1,3,4,6,7],[0,1,2,4,8,9]),
([8],[10]),
(FadeIn,[5], {"shift":5*LEFT}), # oxygen atom
(SpinInFromNothing,[6],{"angle":4*PI}), # left bond
([2],[3]),
([5],[7])
),
run_time=3,
)
self.wait()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment