0

Here's my code

class Formula2(GraphScene):
    CONFIG = {
        "x_min" : 0,
        "x_max" : 10.3,
        "x_tick_frequency": 1,
        "y_min" : 0,
        "y_max" : 10.3,
        "y_tick_frequency": 1,
        "graph_origin" : [-4,-3,0] ,
        "function_color" : RED ,
        "axes_color" : WHITE ,
        "x_labeled_nums" : range(1,10,1),
        "y_labeled_nums" : range(1,10,1)
    }
    def construct(self):
        self.setup_axes(animate=True)
        func_graph = self.get_graph(self.func_to_graph, self.function_color)
        vert_line = Line(start=self.coords_to_point(1,0), color=YELLOW)
        vert_line.add_updater(lambda d:d.put_start_and_end_on(vert_line.start, self.input_to_graph_point(self.point_to_coords(vert_line.start)[0], func_graph)))

        self.play(ShowCreation(func_graph))
        self.play(ShowCreation(vert_line))
        self.play(ApplyMethod(vert_line.shift, RIGHT))

    def func_to_graph(self,x):
        return x

And the updater doesn't work. I want the start of the line be on the x-axis and its end on the function graph. What's the problem with my code?

Derican
  • 49
  • 2

1 Answers1

0
class Formula2(GraphScene):
    CONFIG = {
        "x_min" : 0,
        "x_max" : 10.3,
        "x_tick_frequency": 1,
        "y_min" : 0,
        "y_max" : 10.3,
        "y_tick_frequency": 1,
        "graph_origin" : [-4,-3,0] ,
        "function_color" : RED ,
        "axes_color" : WHITE ,
        "x_labeled_nums" : range(1,10,1),
        "y_labeled_nums" : range(1,10,1)
    }
    def construct(self):
        self.setup_axes(animate=False)
        func_graph = self.get_graph(self.func_to_graph, self.function_color)
        vert_line = Line(start=self.coords_to_point(1,0), color=YELLOW)
        vert_line.add_updater(
            lambda mob: mob.put_start_and_end_on(
                    vert_line.get_start(),
                    func_graph.get_end()
                )
            )


        self.play(ShowCreation(func_graph))
        # add the vert_line because it have a updater method
        self.add(vert_line)
        self.play(ShowCreation(vert_line))
        self.play(ApplyMethod(vert_line.shift, RIGHT))

    def func_to_graph(self,x):
        return x
TheoremOfBeethoven
  • 1,864
  • 6
  • 15
  • Umm It seems that `func_graph.get_end()` doesn't meet my needs. But `get_start` helps. Now I have a problem, that `self.play(ApplyMethod(vert_line.shift, RIGHT))` doesn't work, neither does `move_to` or `put_start_and_end_on`. But `vert_line.shift(RIGHT)` works. How can I solve it? – Derican Feb 08 '20 at 04:00
  • I don't have clear what you want to do, can you be more specific? The `self.play(ApplyMethod(vert_line.shift, RIGHT))` does't work because the `vert_line` have an updater method, you have to suspend it o remove the updater method to modify it again, see [this](https://github.com/3b1b/manim/blob/master/manimlib/mobject/mobject.py#L192-#L223) – TheoremOfBeethoven Feb 08 '20 at 11:34