Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
382 views
in Technique[技术] by (71.8m points)

python - Is it possible to use ReplacementTransform on a graph object in manim?

I'm fairly new to manim

I want to be able to draw a line graph and after the line has drawn, rotate it around its intercept. But right now, the transform is not happening: my code just shows the same unchanging line of graph0 and does not do the ReplacementTransform.

I have also tried pivot, which works, but pivots the line around its centre and even if I could get it to pivot around its intercept, I am not sure how to get it to the exact equation I want for each pivot.

Is there a way to make this line pivot to the different equations I have specified with graph0, graph1, and graph2?

Here's my code

class LinePivot(GraphScene):
CONFIG = {
    "y_max": 40,
    "y_min": 0,
    "x_max": 14,
    "x_min": 0,
    "y_tick_frequency": 5,
    "x_tick_frequency": 1,
    "axes_color": BLACK,
    "y_label_direction": LEFT,
    "x_label_direction": DOWN,
    "label_nums_color": BLACK,
    "camera_config": {
        "background_color": WHITE,
    },
}

def construct(self):
    self.setup_axes()

    graph0 = self.get_graph(lambda x: 5 + 2 * x, color=BLACK)
    graph1 = self.get_graph(lambda x: 5 + 3 * x, color=BLACK)
    graph2 = self.get_graph(lambda x: 5 + 4 * x, color=BLACK)

    self.play(ShowCreation(graph0))
    self.wait()
    ReplacementTransform(graph0, graph1, run_time=1)
    self.wait()
    ReplacementTransform(graph1, graph2, run_time=1)
    self.wait()

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
ReplacementTransform(graph0, graph1, run_time=1)

only creates the transformation but doesn't add it to the scene or render it. You want to instead use

self.play(ReplacementTransform(graph0, graph1), run_time=1)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...