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=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

并且更新程序不起作用。我希望线的起点位于 x 轴上,终点位于函数图上。我的代码有什么问题?

4

1 回答 1

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
于 2020-02-07T12:07:12.237 回答