Ejemplo n.º 1
0
def get_tex_config():
    """
    Returns a dict which should look something like this:
    {
        "executable": "latex",
        "template_file": "tex_template.tex",
        "intermediate_filetype": "dvi",
        "text_to_replace": "YourTextHere",
        "tex_body": "..."
    }
    """
    # Only load once, then save thereafter
    if not SAVED_TEX_CONFIG:
        custom_config = get_custom_config()
        SAVED_TEX_CONFIG.update(custom_config["tex"])
        # Read in template file
        template_filename = os.path.join(
            get_manim_dir(),
            "manimlib",
            "tex_templates",
            SAVED_TEX_CONFIG["template_file"],
        )
        with open(template_filename, "r", encoding="utf-8") as file:
            SAVED_TEX_CONFIG["tex_body"] = file.read()
    return SAVED_TEX_CONFIG
Ejemplo n.º 2
0
def get_customization():
    if not CUSTOMIZATION:
        CUSTOMIZATION.update(config.get_custom_config())
        directories = CUSTOMIZATION["directories"]
        # Unless user has specified otherwise, use the system default temp
        # directory for storing tex files, mobject_data, etc.
        if not directories["temporary_storage"]:
            directories["temporary_storage"] = tempfile.gettempdir()

        # Assumes all shaders are written into manimlib/shaders
        directories["shaders"] = os.path.join(get_manim_dir(), "manimlib",
                                              "shaders")
    return CUSTOMIZATION
def get_tex_config():
    """
    Returns a dict which should look something like this:
    {
        "text_to_replace": "YourTextHere",
        "template_file": "tex_template.tex",
        "tex_body": "..."
    }
    """
    # Only load once, then save thereafter
    if not SAVED_TEX_CONFIG:
        custom_config = get_custom_config()
        SAVED_TEX_CONFIG.update(custom_config["tex"])
    return SAVED_TEX_CONFIG
Ejemplo n.º 4
0
    def embed(self, close_scene_on_exit: bool = True) -> None:
        if not self.preview:
            # If the scene is just being
            # written, ignore embed calls
            return
        self.stop_skipping()
        self.linger_after_completion = False
        self.update_frame()

        # Save scene state at the point of embedding
        self.save_state()

        from IPython.terminal.embed import InteractiveShellEmbed
        shell = InteractiveShellEmbed()
        # Have the frame update after each command
        shell.events.register('post_run_cell',
                              lambda *a, **kw: self.refresh_static_mobjects())
        shell.events.register('post_run_cell',
                              lambda *a, **kw: self.update_frame())
        # Use the locals of the caller as the local namespace
        # once embedded, and add a few custom shortcuts
        local_ns = inspect.currentframe().f_back.f_locals
        local_ns["touch"] = self.interact
        local_ns["i2g"] = self.ids_to_group
        for term in ("play", "wait", "add", "remove", "clear", "save_state",
                     "restore"):
            local_ns[term] = getattr(self, term)
        log.info(
            "Tips: Now the embed iPython terminal is open. But you can't interact with"
            " the window directly. To do so, you need to type `touch()` or `self.interact()`"
        )
        exec(get_custom_config()["universal_import_line"])
        shell(local_ns=local_ns, stack_depth=2)
        # End scene when exiting an embed
        if close_scene_on_exit:
            raise EndSceneEarlyException()
Ejemplo n.º 5
0
 def construct(self):
     exec(get_custom_config()["universal_import_line"])
     self.embed()
Ejemplo n.º 6
0
    def construct(self):
        #get the properties of Mobjects
        print(Dot.CONFIG.keys())
        #get the global config
        from manimlib.config import get_custom_config
        config = get_custom_config()

        ## graphical Objects
        circle = Circle(color=RED, radius=0.2)
        square = Square(color=BLUE)
        triangle = Triangle(color=PINK)
        point = Point(np.array([0, 0]))
        dot = Dot(np.array([0, 0]), radius=0.1)
        rectangle = Rectangle(height=2, width=3)
        edge = Line(
            start_coord,
            end_coord,
            buff=1,
            stroke_color=RED,
            stroke_width=1,
        )
        a = Axes(x_min=-3,
                 x_max=3,
                 x_axis_width=15,
                 x_tick_frequency=1,
                 x_leftmost_tick=None,
                 x_axis_label=None,
                 y_min=-3,
                 y_max=3,
                 y_axis_height=15,
                 y_tick_frequency=1,
                 y_bottom_tick=None,
                 y_labeled_nums=None,
                 y_axis_label=None,
                 axes_color=WHITE,
                 graph_origin=1 * DOWN + 1 * LEFT,
                 exclude_zero_label=True,
                 num_graph_anchor_points=25,
                 default_graph_colors=[BLUE, GREEN, YELLOW],
                 default_derivative_color=GREEN,
                 default_input_color=YELLOW,
                 default_riemann_start_color=BLUE,
                 default_riemann_end_color=GREEN,
                 function_color=WHITE,
                 area_opacity=0.8,
                 num_rects=50,
                 include_tip=True,
                 axis_config={"include_tip": False},
                 x_axis_config={"x_min": -40},
                 y_axis_config={})
        n = NumberLine()
        f = FunctionGraph(lambda x: x**2, x_min=3, x_max=3, color=BLUE)
        f = ParametricFunction(self.func, t_min=-3, t_max=3, color=BLUE)

        # graphical actions

        #Grouping
        VGroup(
            circle, triangle, square
        )  # groups multiple objects, color shifting rotation is applied to all elements
        Group()  # groups for objects not base on bezier curves

        #Animations/Effects
        Write(eq1)  #writes an equation
        ShowCreation(circle)
        FadeIn(circle)
        FadeOut(circle)
        FadeInFromPoint(circle, point)
        FadeIn(circle, shift=LEFT)  #shift in from the right side
        ReplacementTransform()
        ShowTextWordByWord(eq1)  #writes the text 1 by 1

        ## Latex equations Objects
        eq1 = TexText(r"$\frac{dJ}{d\theta} = \textbf{W}\vec{x} $")

        ## mobject methods
        circle.set_x()
        circle.get_x()
        circle.add_updater(lambda mobj: mobj.set_x(mobj.get_x() + 1))
        # mobject transformation
        circle.set_fill(PINK, opacity=0.5)  # sets the circle fill color
        eq1.shift(UP)  # shifts the mobject up relative to the current position
        circle.move_to(self, point_or_mobject=point)
        circle.move_to(self, point_or_mobject=square)

        #Scene methods
        self.play(
            Write(eq1), run_time=3
        )  #play the given animation, run_time modifies the duration of the animation
        self.play(circle.shift,
                  UP)  #play the shifting of the circle as animation
        self.add(eq1)  #add an object to a Scene without animation
        self.remove(eq1)  # removes the object from the screen
        self.wait(1)  #pauses the animtion for the given amount of seconds

        #change camera settings
        self.play(
            # Set the size with the width of a object
            self.camera.frame.set_width,
            20,
        )