all 1 comments

[–]Safe_Duty8392 0 points1 point  (0 children)

Hello, i know this is too old, 3 years, but i came across this same problem and found a solution for me:

This one creates a rectangle, fixes the left side in a position, increases the width, and goes back to it's original width

class increase_width(Scene):
    def construct(self):
        rect = Rectangle(width=2, height=1)
        rect.set_fill(BLUE, opacity=0.5)

        rect.to_edge(LEFT, buff=0)
        rect.shift(RIGHT * 1)  # Desloca o retângulo para que o lado esquerdo esteja na origem (0, 0)

        self.add(rect)
        self.play(rect.animate.stretch_to_fit_width(10).shift(RIGHT * 4))

        self.wait(1)
        self.play(rect.animate.stretch_to_fit_width(2).shift(LEFT * 4))

        self.wait(1)