How to use manimlib - 10 common examples

To help you get started, we’ve selected a few manimlib examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github 3b1b / manim / manimlib / mobject / svg / svg_mobject.py View on Github external
from manimlib.utils.color import *
from manimlib.utils.config_ops import digest_config
from manimlib.utils.config_ops import digest_locals


def string_to_numbers(num_string):
    num_string = num_string.replace("-", ",-")
    num_string = num_string.replace("e,-", "e-")
    return [
        float(s)
        for s in re.split("[ ,]", num_string)
        if s != ""
    ]


class SVGMobject(VMobject):
    CONFIG = {
        "should_center": True,
        "height": 2,
        "width": None,
        # Must be filled in in a subclass, or when called
        "file_name": None,
        "unpack_groups": True,  # if False, creates a hierarchy of VGroups
        "stroke_width": DEFAULT_STROKE_WIDTH,
        "fill_opacity": 1.0,
        # "fill_color" : LIGHT_GREY,
    }

    def __init__(self, file_name=None, **kwargs):
        digest_config(self, kwargs)
        self.file_name = file_name or self.file_name
        self.ensure_valid_file()
github Elteoremadebeethoven / MyAnimations / omega_creature / omega_creature_class.py View on Github external
def look(self, direction):
        norm = get_norm(direction)
        if norm == 0:
            return
        direction /= norm
        self.purposeful_looking_direction = direction
        for pupil, eye in zip(self.pupils.split(), self.eyes.split()):
            c = eye.get_center()
            right = eye.get_right() - c
            up = eye.get_top() - c
            vect = direction[0] * right + direction[1] * up
            v_norm = get_norm(vect)
            p_radius = 0.5 * pupil.get_width()
            vect *= (v_norm - 0.75 * p_radius) / v_norm
            pupil.move_to(c + vect)
        self.pupils[1].align_to(self.pupils[0], DOWN)
        return self
github 3b1b / manim / manimlib / for_3b1b_videos / pi_creature.py View on Github external
def look(self, direction):
        norm = get_norm(direction)
        if norm == 0:
            return
        direction /= norm
        self.purposeful_looking_direction = direction
        for pupil, eye in zip(self.pupils.split(), self.eyes.split()):
            c = eye.get_center()
            right = eye.get_right() - c
            up = eye.get_top() - c
            vect = direction[0] * right + direction[1] * up
            v_norm = get_norm(vect)
            p_radius = 0.5 * pupil.get_width()
            vect *= (v_norm - 0.75 * p_radius) / v_norm
            pupil.move_to(c + vect)
        self.pupils[1].align_to(self.pupils[0], DOWN)
        return self
github 3b1b / manim / manimlib / for_3b1b_videos / pi_creature.py View on Github external
def look(self, direction):
        norm = get_norm(direction)
        if norm == 0:
            return
        direction /= norm
        self.purposeful_looking_direction = direction
        for pupil, eye in zip(self.pupils.split(), self.eyes.split()):
            c = eye.get_center()
            right = eye.get_right() - c
            up = eye.get_top() - c
            vect = direction[0] * right + direction[1] * up
            v_norm = get_norm(vect)
            p_radius = 0.5 * pupil.get_width()
            vect *= (v_norm - 0.75 * p_radius) / v_norm
            pupil.move_to(c + vect)
        self.pupils[1].align_to(self.pupils[0], DOWN)
        return self
github Solara570 / demo-solara / calissons.py View on Github external
def show_counter(self):
        counters = VGroup(*[rhombus.get_counter_tex() for rhombus in self.rhombi])
        three_types_text = self.bg_texts[2]
        try_tiling_text, remark = self.bg_texts[3]
        self.play(
            FadeOut(self.reflines),
            ApplyMethod(self.rhombi.set_fill, None, 1),
            Write(three_types_text),
            run_time = 2
        )
        self.wait()
        self.play(Write(try_tiling_text), run_time = 2)
        self.play(Write(remark), run_time = 1)
        self.wait()
        self.play(FadeIn(counters), run_time = 1)
        self.wait(4)
        self.counters = counters
github 3b1b / manim / manimlib / scene / vector_space_scene.py View on Github external
)
        y_coord_start = self.position_y_coordinate(
            y_coord.copy(), y_line, vector
        )
        brackets = array.get_brackets()

        if show_creation:
            self.play(ShowCreation(arrow))
        self.play(
            ShowCreation(x_line),
            Write(x_coord_start),
            run_time=1
        )
        self.play(
            ShowCreation(y_line),
            Write(y_coord_start),
            run_time=1
        )
        self.wait()
        self.play(
            Transform(x_coord_start, x_coord, lag_ratio=0),
            Transform(y_coord_start, y_coord, lag_ratio=0),
            Write(brackets, run_time=1),
        )
        self.wait()

        self.remove(x_coord_start, y_coord_start, brackets)
        self.add(array)
        if clean_up:
            self.clear()
            self.add(*starting_mobjects)
        return array, x_line, y_line
github Solara570 / demo-solara / calissons.py View on Github external
def proof_part_1(self):
        proof_text, paint_text, and_text, perspective_text = self.proof_texts
        self.play(Write(proof_text), run_time = 1)
        self.wait(4)
        self.play(Write(paint_text), run_time = 1)
        self.wait(3)
        self.play(FadeIn(self.imagine_3d_text), run_time = 1)
        self.wait(6)
        self.play(FadeOut(self.imagine_3d_text), run_time = 1)
        self.wait()
        self.play(Write(VGroup(and_text, perspective_text), run_time = 1))
        self.wait()
github Solara570 / demo-solara / calissons.py View on Github external
def setup_tiling(self):
        self.wait(2)
        self.set_camera_orientation(*DIAG_POS)
        self.tiling = CalissonTiling3D(dimension = 5, pattern = MAA_PATTERN)
        self.play(Write(self.tiling, rate_func = smooth), run_time = 3)
        self.wait(2)
github Solara570 / demo-solara / short / kkd / kkd.py View on Github external
lhs.set_color(GREEN)
        rhs.set_color(BLUE)

        prod_tex_rect = SurroundingRectangle(self.prod_tex, color = GREEN)
        sum_tex_rect = SurroundingRectangle(self.sum_tex, color = BLUE)
        self.play(
            ShowCreationThenDestruction(prod_tex_rect),
            Write(lhs),
            run_time = 2,
        )
        self.play(
            ShowCreationThenDestruction(sum_tex_rect),
            Write(rhs),
            run_time = 2,
        )
        self.play(Write(equal))
        self.wait(3)
github Solara570 / demo-solara / short / kkd / kkd.py View on Github external
Write(self.get_plus_symbol(n-1)),
                    )
                self.wait()
            # And show the result for the remaining terms
            else:
                self.play(
                    Transform(
                        VGroup(
                            self.get_highlighted_terms(n).deepcopy(),
                            self.get_times_symbols().deepcopy(),
                            self.get_cdots_symbol().deepcopy(),
                        ),
                        self.get_sum_term(n),
                        lag_ratio = 0,
                    ),
                    Write(self.get_plus_symbol(n-1)),
                )
        # Add \cdots to the end.
        self.wait()
        self.play(
            FadeOut(rects),
            Write(self.sum_tex[-1][-4:])
        )
        self.wait()