Introduction

Welcome to circuitanim, an extension to 3b1b’s manim python library. Much like manim simplifies animating mathematical obects, circuitanim simplifies animating circuits. As seen below, with only a few lines of code, you can render a complete circuit scene.

from manimlib.imports import *
from circuitanimlib.circuit import *
class DrawCircuit(Scene):
  def construct(self):
    res = Resistor()
    cap = Capacitor()
    batt = Battery()

    batt.rotate(PI/2)
    cap.rotate(-PI/2)
    cap.shift(RIGHT*3)
    res.shift(2*LEFT + UP*3)
    batt.shift(3*LEFT)


    circ = Circuit()
    circ.connect(batt.get_right(),res.get_left())
    circ.connect(res.get_right(),cap.get_left(),pin_top=True)
    circ.connect_right_to_left(cap.get_right(),batt.get_left())
    circ.render()
    
    self.play(ShowCreation(batt),ShowCreation(res),ShowCreation(cap),ShowCreation(circ),run_time=3)

Set Up

For up-to-date installation, see the Github readme which can be found here.

Driver Classes

Circuit

class Circuit(VMobject)

The circuit class is what glues together all of the electrical components in a scene.

Methods

  • connect(point1,point2,pin_top=False) Method for connecting electrical components, preferably from left to right. The function takes in two terminal coordinates to connect. The terminal coordinates can be found using methods specific to the electrical component. The optional parameter pin_top=False just specifies whether the anchor point of the 90 degree bend should lie in the horizontal axis of the first point (False) or second point(True).
  • connect_right_to_left(point1,point2) Method for connecting electrical components, specifically designed for when the first terminal (point) lies to the right of the second terminal.
  • render() Adds all points onto the Mobject for rendering.

CircuitComponent

class CircuitComponent(VMobject)

The CircuitComponent class is the parent class of all circuit components, except for logic gates.

Methods

  • get_left() Method for getting coordinate of the leftmost terminal (point). Returns a 3D numpy array.
  • get_right() Method for getting coordinate of rightmost terminal (point). Returns a 3D numpy array.

LogicGate

class LogicGate(VMobject)

The LogicGate class is the parent class of the 8 available logic gates.

Methods

  • get_inputA() Method for getting coordinate of the first input terminal (point). Returns a 3D numpy array.
  • get_inputB() Method for getting coordinate of the second input terminal (point). Returns a 3D numpy array.
  • get_output() Method for getting coordinate of the output terminal (point). Returns a 3D numpy array.

Basic Electrical Components

Capacitor

By default, a non-polar capacitor is rendered. If you wish to render a polar capacitor, you can pass the optional parameter is_polar and set it equal to True

from manimlib.imports import *
from circuitanimlib.circuit import *
class Sample(Scene):
  def construct(self):
    obj = Capacitor()
    self.play(ShowCreation(obj))
          
from manimlib.imports import *
from circuitanimlib.circuit import *
class Sample(Scene):
  def construct(self):
    obj = Capacitor(is_polar=True)
    self.play(ShowCreation(obj))
          

Diode

By default, a standard diode is rendered. If you wish to change the diode type, in the constructor you can pass the optional parameter diode_type and specify one of the supported enums: DIODE_DEFAULT, DIODE_ZENER, DIODE_SCHOTTKY.

from manimlib.imports import *
from circuitanimlib.circuit import *
class Sample(Scene):
  def construct(self):
    obj = Diode()
    self.play(ShowCreation(obj))
          
from manimlib.imports import *
from circuitanimlib.circuit import *
class Sample(Scene):
  def construct(self):
    obj = Diode(diode_type=DIODE_ZENER)
    self.play(ShowCreation(obj))
          
from manimlib.imports import *
from circuitanimlib.circuit import *
class Sample(Scene):
  def construct(self):
    obj = Diode(diode_type=DIODE_SCHOTTKY)
    self.play(ShowCreation(obj))
          

Inductor

from manimlib.imports import *
from circuitanimlib.circuit import *
class Sample(Scene):
  def construct(self):
    obj = Inductor()
    self.play(ShowCreation(obj))
          

Resistor

from manimlib.imports import *
from circuitanimlib.circuit import *
class Sample(Scene):
  def construct(self):
    obj = Resistor()
    self.play(ShowCreation(obj))
          

Logic Gates

AND & NAND

from manimlib.imports import *
from circuitanimlib.logic import *
class Sample(Scene):
  def construct(self):
    obj = AND()
    self.play(ShowCreation(obj))
          
from manimlib.imports import *
from circuitanimlib.logic import *
class Sample(Scene):
  def construct(self):
    obj = NAND()
    self.play(ShowCreation(obj))
          

OR & NOR

from manimlib.imports import *
from circuitanimlib.logic import *
class Sample(Scene):
  def construct(self):
    obj = OR()
    self.play(ShowCreation(obj))
          
from manimlib.imports import *
from circuitanimlib.logic import *
class Sample(Scene):
  def construct(self):
    obj = NOR()
    self.play(ShowCreation(obj))
          

XOR & XNOR

from manimlib.imports import *
from circuitanimlib.logic import *
class Sample(Scene):
  def construct(self):
    obj = XOR()
    self.play(ShowCreation(obj))
          
from manimlib.imports import *
from circuitanimlib.logic import *
class Sample(Scene):
  def construct(self):
    obj = XNOR()
    self.play(ShowCreation(obj))
          

Buffer & NOT

from manimlib.imports import *
from circuitanimlib.logic import *
class Sample(Scene):
  def construct(self):
    obj = Buffer()
    self.play(ShowCreation(obj))
          
from manimlib.imports import *
from circuitanimlib.logic import *
class Sample(Scene):
  def construct(self):
    obj = NOT()
    self.play(ShowCreation(obj))
          

Power Sources

AC Source

from manimlib.imports import *
from circuitanimlib.circuit import *
class Sample(Scene):
  def construct(self):
    obj = ACSource()
    self.play(ShowCreation(obj))
          

Battery

from manimlib.imports import *
from circuitanimlib.circuit import *
class Sample(Scene):
  def construct(self):
    obj = Battery()
    self.play(ShowCreation(obj))
          

Current Source

By default, the current source is rendered as an independent current source. If you would like to render it as a dependent current source, then in the constructor just pass in the optional parameter is_dependent and set it to True.

from manimlib.imports import *
from circuitanimlib.circuit import *
class Sample(Scene):
  def construct(self):
    obj = CurrentSource()
    self.play(ShowCreation(obj))
          
from manimlib.imports import *
from circuitanimlib.circuit import *
class Sample(Scene):
  def construct(self):
    obj = CurrentSource(is_dependent=True)
    self.play(ShowCreation(obj))
          

Voltage Source

By default, the voltage source is rendered as an independent voltage source. If you would like to render it as a dependent voltage source, then in the constructor just pass in the optional parameter is_dependent and set it to True.

from manimlib.imports import *
from circuitanimlib.circuit import *
class Sample(Scene):
  def construct(self):
    obj = VoltageSource()
    self.play(ShowCreation(obj))
          
from manimlib.imports import *
from circuitanimlib.circuit import *
class Sample(Scene):
  def construct(self):
    obj = VoltageSource(is_dependent=True)
    self.play(ShowCreation(obj))
          

Transistors

Note: Transistors have more than two terminals so avoid the use of get_left() and get_right(). Instead, use methods specific to the transistor type

BJTs

By default, the bjt is rendered as npn. If you would like to render a pnp bjt, then in the constructor just pass in the optional parameter is_pnp and set it to False.

from manimlib.imports import *
from circuitanimlib.circuit import *
class Sample(Scene):
  def construct(self):
    obj = Bjt()
    self.play(ShowCreation(obj))
          
from manimlib.imports import *
from circuitanimlib.circuit import *
class Sample(Scene):
  def construct(self):
    obj = Bjt(is_pnp=False)
    self.play(ShowCreation(obj))
          

Methods

  • get_base() Returns coordinates of the base terminal
  • get_collector() Returns coordinates of the collector terminal
  • get_emitter() Returns coordinates of the emitter terminal

Mosfets

By default, the mosfet is rendered as nmos. If you would like to render it as pmos, then in the constructor just pass in the optional parameter is_nmos and set it to False.

from manimlib.imports import *
from circuitanimlib.circuit import *
class Sample(Scene):
  def construct(self):
    obj = Mosfet()
    self.play(ShowCreation(obj))
          
from manimlib.imports import *
from circuitanimlib.circuit import *
class Sample(Scene):
  def construct(self):
    obj = Mosfet(is_nmos=False)
    self.play(ShowCreation(obj))
          

Methods

  • get_drain() Returns coordinates of the drain terminal
  • get_gate() Returns coordinates of the gate terminal
  • get_source() Returns coordinates of the source terminal