Skip to content

Instantly share code, notes, and snippets.

@uwezi
Created March 19, 2023 11:47
Show Gist options
  • Save uwezi/6f66679acec76da059ea37d1096d92d9 to your computer and use it in GitHub Desktop.
Save uwezi/6f66679acec76da059ea37d1096d92d9 to your computer and use it in GitHub Desktop.
[Circuitikz in Manim] How to use circuitikz in Manim #latex #tikz #manim #electronics #circuitikz
# https://discord.com/channels/581738731934056449/1048986980769333329/1062860351567319062
# https://discord.com/channels/581738731934056449/1062828056235999242/1062836565983903835
# import from KiCAD and LTspice: https://github.com/uwezi/circuitikz_import
from manim import *
class circuit(Scene):
def construct(self):
template = TexTemplate()
template.add_to_preamble(r"\usepackage{tikz}\usepackage[europeanresistors,americaninductors]{circuitikz}")
c = Tex(
r"""[american voltages, baseline=(current bounding box.center)]
\draw (0,0) to [R, l=$R$] (6,0) to [V, l=$E$] (6,2) to [L, l=$L$] (0,2);""",
tex_environment="circuitikz",
tex_template=template,
stroke_width=2,
fill_opacity=0,
stroke_opacity=1,
)
self.play(FadeIn(c, shift=UP, target_position=ORIGIN), run_time=3)
self.play(ApplyWave(c[0]))
self.wait(2)
class circuit2(Scene):
def construct(self):
template = TexTemplate()
template.add_to_preamble(r"\usepackage{tikz}\usepackage{circuitikz}")
c = Tex(
r"""[american voltages, baseline=(current bounding box.center)]
\draw (0,0)
to[V=$V{Th}$] (0,2)
to[R=$R_{Th}$] (2.5,2)
to[short,i=$I$, -o] (4,2)
to[short] (4.5,2)
(0,0) to[short, -o] (4,0)
to[short] (4.5,0);""",
tex_environment="circuitikz",
tex_template=template,
stroke_width=2,
fill_opacity=0,
stroke_opacity=1,
)
self.play(FadeIn(c, shift=UP, target_position=ORIGIN), run_time=3)
self.play(ApplyWave(c[0]))
#self.play(Indicate(c[2], color=TEAL), run_time=2)
#self.play(Circumscribe(c[4], fade_out=True, color=BLUE))
self.wait(2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment