如何在图形转换期间跟踪参数

How to track parameter during Transformation of graph

假设我正在尝试将一个函数转换为另一个函数: y=x -> y=2x

有什么方法可以让我在动画期间 'follow' m 参数,并在屏幕上显示它?

示例:GIF of me doing it in GeoGebra

看我的教程here

更多 ValueTracker 个示例 here

解决方案:

class ValueTrackerExample(Scene):
    def construct(self):
        # SETUP GRAPH
        axes = Axes()
        m_tracker = ValueTracker(1)
        func = lambda m: lambda x: m * x
        graph = VMobject()
        graph_kwargs = {"color": GREEN}
        # SETUP FORMULA
        decimal = DecimalNumber(1,num_decimals=2)
        formula = TexMobject("y = ", "x")
        # ---- Arrange position of formula
        formula.to_corner(DR)
        formula[0].shift(LEFT * 1.1)
        decimal.next_to(formula[1],LEFT,aligned_edge=DOWN)
        # SET UPDATERS
        def update_graph(mob):
            mob.become(
                axes.get_graph(
                    func(m_tracker.get_value()),
                    **graph_kwargs
                )
            )
        # SET INITIAL STATE OF GRAPH
        update_graph(graph)
        graph.add_updater(update_graph)
        self.add(axes)
        self.play(ShowCreation(graph),Write(VGroup(formula[0],decimal,formula[1])))
        self.play(
            m_tracker.set_value, 2,
            ChangeDecimalToValue(decimal,2)
        )