How to use the manimlib.mobject.types.vectorized_mobject.VMobject function in manimlib

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 3b1b / manim / manimlib / once_useful_constructs / fractals.py View on Github external
def init_colors(self):
        VMobject.init_colors(self)
        internal_pis = [
            pi
            for pi in self.get_family()
            if isinstance(pi, PiCreature)
        ]
        random.seed(self.random_seed)
        for pi in reversed(internal_pis):
            color = random.choice(self.colors)
            pi.set_color(color)
            pi.set_stroke(color, width=0)
github 3b1b / manim / manimlib / mobject / geometry.py View on Github external
return Line.get_start(self)

    def get_end(self):
        if len(self.submobjects) > 0:
            return self.submobjects[-1].get_end()
        else:
            return Line.get_end(self)

    def get_first_handle(self):
        return self.submobjects[0].points[1]

    def get_last_handle(self):
        return self.submobjects[-1].points[-2]


class Elbow(VMobject):
    CONFIG = {
        "width": 0.2,
        "angle": 0,
    }

    def __init__(self, **kwargs):
        VMobject.__init__(self, **kwargs)
        self.set_points_as_corners([UP, UP + RIGHT, RIGHT])
        self.set_width(self.width, about_point=ORIGIN)
        self.rotate(self.angle, about_point=ORIGIN)


class Arrow(Line):
    CONFIG = {
        "stroke_width": 6,
        "buff": MED_SMALL_BUFF,
github 3b1b / manim / manimlib / mobject / geometry.py View on Github external
def scale(self, factor, **kwargs):
        if self.get_length() == 0:
            return self

        has_tip = self.has_tip()
        has_start_tip = self.has_start_tip()
        if has_tip or has_start_tip:
            old_tips = self.pop_tips()

        VMobject.scale(self, factor, **kwargs)
        self.set_stroke_width_from_length()

        # So horribly confusing, must redo
        if has_tip:
            self.add_tip()
            old_tips[0].points[:, :] = self.tip.points
            self.remove(self.tip)
            self.tip = old_tips[0]
            self.add(self.tip)
        if has_start_tip:
            self.add_tip(at_start=True)
            old_tips[1].points[:, :] = self.start_tip.points
            self.remove(self.start_tip)
            self.start_tip = old_tips[1]
            self.add(self.start_tip)
        return self
github 3b1b / manim / manimlib / once_useful_constructs / light.py View on Github external
light.submobjects = light.submobjects[::-1]


class Lighthouse(SVGMobject):
    CONFIG = {
        "file_name": "lighthouse",
        "height": LIGHTHOUSE_HEIGHT,
        "fill_color": WHITE,
        "fill_opacity": 1.0,
    }

    def move_to(self, point):
        self.next_to(point, DOWN, buff=0)


class AmbientLight(VMobject):

    # Parameters are:
    # * a source point
    # * an opacity function
    # * a light color
    # * a max opacity
    # * a radius (larger than the opacity's dropoff length)
    # * the number of subdivisions (levels, annuli)

    CONFIG = {
        "source_point": VectorizedPoint(location=ORIGIN, stroke_width=0, fill_opacity=0),
        "opacity_function": lambda r: 1.0 / (r + 1.0)**2,
        "color": LIGHT_COLOR,
        "max_opacity": 1.0,
        "num_levels": NUM_LEVELS,
        "radius": 5.0
github Solara570 / demo-solara / short / ford_circles.py View on Github external
from manimlib.mobject.geometry import Circle, Rectangle, Arrow
from manimlib.mobject.coordinate_systems import Axes
from manimlib.scene.scene import Scene


def is_coprime(p, q):
    return math.gcd(p, q) == 1

def get_coprime_numers_by_denom(q):
    return [0, 1] if q == 1 else [p for p in range(1, q) if is_coprime(p, q)]

def get_stroke_width_by_height(height, thres = 1):
    return 1 if height > thres else height


class AssembledFraction(VMobject):
    CONFIG = {
        "stroke_width": 0,
        "fill_opacity": 1.0,
    }
    def __init__(self, p, q, **kwargs):
        self.p = str(p)
        self.q = str(q)
        super(AssembledFraction, self).__init__(**kwargs)

    def generate_points(self):
        numer = TexMobject(self.p)
        denom = TexMobject(self.q)
        line = Rectangle(height = 0.02)
        line.set_width(max(numer.get_width(), denom.get_width()) * 1.1, stretch = True)
        self.add(numer, line, denom)
        self.arrange_submobjects(DOWN, buff = 0.15)
github 3b1b / manim / manimlib / mobject / types / vectorized_mobject.py View on Github external
def __init__(self, vmobject, **kwargs):
        VGroup.__init__(self, **kwargs)
        tuples = vmobject.get_cubic_bezier_tuples()
        for tup in tuples:
            part = VMobject()
            part.set_points(tup)
            part.match_style(vmobject)
            self.add(part)
github 3b1b / manim / manimlib / mobject / changing.py View on Github external
fading.set_stroke(
                color=colors[index - 1],
                width=(1 - fade_alpha) * msw
            )

        self.total_time += dt

    def full_family_become_partial(self, mob1, mob2, a, b):
        family1 = mob1.family_members_with_points()
        family2 = mob2.family_members_with_points()
        for sm1, sm2 in zip(family1, family2):
            sm1.pointwise_become_partial(sm2, a, b)
        return self


class TracedPath(VMobject):
    CONFIG = {
        "stroke_width": 2,
        "stroke_color": WHITE,
        "min_distance_to_new_point": 0.1,
    }

    def __init__(self, traced_point_func, **kwargs):
        super().__init__(**kwargs)
        self.traced_point_func = traced_point_func
        self.add_updater(lambda m: m.update_path())

    def update_path(self):
        new_point = self.traced_point_func()
        if self.has_no_points():
            self.start_new_path(new_point)
            self.add_line_to(new_point)
github Solara570 / demo-solara / custom / custom_mobjects.py View on Github external
return symbol


class TickButton(Button):
    CONFIG = {
        "color" : GREEN,
    }
    def generate_symbol(self):
        symbol = TexMobject("\\checkmark")
        symbol.set_color(self.color)
        symbol.set_height(self.inner_radius)
        return symbol


## Danger Sign
class HollowTriangle(VMobject):
    CONFIG = {
        "inner_height" : 3.5,
        "outer_height" : 5,
        "color" : RED,
        "fill_opacity" : 1,
        "stroke_width" : 0,
        "mark_paths_closed" : False,
        "propagate_style_to_family" : True,
    }
    def generate_points(self):
        self.points = []
        inner_tri = RegularPolygon(n = 3, start_angle = np.pi/2)
        outer_tri = RegularPolygon(n = 3, start_angle = np.pi/2)
        inner_tri.flip()
        inner_tri.set_height(self.inner_height, about_point = ORIGIN)
        outer_tri.set_height(self.outer_height, about_point = ORIGIN)
github 3b1b / manim / manimlib / mobject / geometry.py View on Github external
Arrow.__init__(self, ORIGIN, direction, **kwargs)


class DoubleArrow(Arrow):
    def __init__(self, *args, **kwargs):
        Arrow.__init__(self, *args, **kwargs)
        self.add_tip(at_start=True)


class CubicBezier(VMobject):
    def __init__(self, points, **kwargs):
        VMobject.__init__(self, **kwargs)
        self.set_points(points)


class Polygon(VMobject):
    CONFIG = {
        "color": BLUE,
    }

    def __init__(self, *vertices, **kwargs):
        VMobject.__init__(self, **kwargs)
        self.set_points_as_corners(
            [*vertices, vertices[0]]
        )

    def get_vertices(self):
        return self.get_start_anchors()

    def round_corners(self, radius=0.5):
        vertices = self.get_vertices()
        arcs = []