Skip to content

Instantly share code, notes, and snippets.

@Elteoremadebeethoven
Created October 28, 2020 03:41
Show Gist options
  • Save Elteoremadebeethoven/a3cd4832b3ca051f569ca762d3f885b2 to your computer and use it in GitHub Desktop.
Save Elteoremadebeethoven/a3cd4832b3ca051f569ca762d3f885b2 to your computer and use it in GitHub Desktop.
from manim import *
# Change background color
# config["background_color"] = GRAY
# config["frame_rate"] = 25
# FRAME_HEIGHT = config["frame_height"]
class WriteTex(Scene):
def construct(self):
tex = VGroup(
# TextMobject
Tex("Hello world!"),
# TexMobject
MathTex("\\frac{x}{y}"),
# Text
CairoText("This is a test", font="Arial")
)
tex.arrange(DOWN)
tex.scale(1.7)
self.play(Write(tex))
# ------------------------------------------------
class CreateATexTemplate(Scene):
def construct(self):
# Create a template
myTemplate = TexTemplate()
# Add new package
myTemplate.add_to_preamble(r"\usepackage{mathrsfs}")
tex = Tex(r'$\mathscr{H} \rightarrow \mathbb{H}$}', tex_template=myTemplate).scale(3)
self.add(tex)
basic_preamble = r"""
\usepackage[english]{babel}
\usepackage{amsmath}
\usepackage{amssymb}
"""
def BTeX(*args,**kwargs):
return Tex(*args,tex_template=TexTemplate(preamble=basic_preamble),**kwargs)
class BasicTexTemplate(Scene):
def construct(self):
tex = BTeX("This is a basic \\TeX")
tex.scale(1.5)
self.add(tex)
# Save this in custom_tex_template.tex
# \documentclass[preview]{standalone}
# \usepackage[english]{babel}
# \usepackage{amsmath}
# \usepackage{amssymb}
# \newcommand{\CustomTeX}{This is a custom tex}
# \begin{document}
# YourTextHere
# \end{document}
# Render: manim Test.py CustomTexTemplate --tex_template custom_tex_template.tex -ps
class CustomTexTemplate(Scene):
def construct(self):
tex = Tex("\\CustomTeX").scale(1.5)
self.add(tex)
# ----------------------------------------------
from manim.mobject.geometry import ArrowTriangleTip, ArrowSquareTip, ArrowSquareFilledTip,\
ArrowCircleTip, ArrowCircleFilledTip
class ExampleArrowTips(Scene):
def construct(self):
a00 = Arrow(start=[-2, 3, 0], end=[2, 3, 0], color=YELLOW)
a11 = Arrow(start=[-2, 2, 0], end=[2, 2, 0], tip_shape=ArrowTriangleTip)
a12 = Arrow(start=[-2, 1, 0], end=[2, 1, 0])
a21 = Arrow(start=[-2, 0, 0], end=[2, 0, 0], tip_shape=ArrowSquareTip)
a22 = Arrow([-2, -1, 0], [2, -1, 0], tip_shape=ArrowSquareFilledTip)
a31 = Arrow([-2, -2, 0], [2, -2, 0], tip_shape=ArrowCircleTip)
a32 = Arrow([-2, -3, 0], [2, -3, 0], tip_shape=ArrowCircleFilledTip)
b11 = a11.copy().scale(0.5, scale_tips=True).next_to(a11, RIGHT)
b12 = a12.copy().scale(0.5, scale_tips=True).next_to(a12, RIGHT)
b21 = a21.copy().scale(0.5, scale_tips=True).next_to(a21, RIGHT)
self.add(a00, a11, a12, a21, a22, a31, a32, b11, b12, b21)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment