Search code examples
pythonpython-3.xmanim

Add buff only in one end of a manim line / arrow


I am connecting two rectangles with a line with a tip or an arrow (it doesn't matter which one). I only want buff at the end of the arrow, not both start and end.

from manim import *

class MyScene(Scene):
    def construct(self):
        rect1 = Rectangle(color=WHITE, height=0.75, width=1.5).to_edge(LEFT)
        rect2 = Rectangle(color=WHITE, height=0.75, width=1.5).next_to(rect1, buff=1.5)

        arrow = Line(start=rect1.get_right(), end=rect2.get_left(), buff=0.1).add_tip()
        # Or
        # arrow = Arrow(start=rect1.get_right(), end=rect2.get_left(), buff=0.1)

        self.play(Create(rect1))
        self.play(Create(rect2))
        self.play(Create(arrow))
        self.wait(2)

As you can see in the picture, there is a buff between the left rectangle and the arrow and the right rectangle and the arrow. I only want the second one.

Picture create by manim as an example

One solution that comes to mind is that I set buff=0 and change the end position of the arrow to create the desired buff manually, but I was hoping to find a better and cleaner solution.


Solution

  • Unfortunately buff is a symmetric quantity. You'll have to modify the end points manually to get the desired effect.