manim icon indicating copy to clipboard operation
manim copied to clipboard

Drop Shadow for Mobjects

Open Ahmed-H-N opened this issue 1 year ago • 3 comments

Description of proposed feature

Adding drop shadow to mobjects. The addition of a drop shadow feature for mobjects in Manim would greatly enhance the visual appeal and depth of animations created using the library.

Ahmed-H-N avatar Feb 07 '24 22:02 Ahmed-H-N

This has been discussed on Discord: https://discord.com/channels/581738731934056449/1173280309601636483/1173280309601636483

The solution presented there is by cloning your objects which are supposed to cast a shadow. Implementing a true blurred shadow is not easy given how objects and scenes are rendered in Manim.

def add_shadow(mobject, color=BLACK, opacity=0.2, shift=(0.2, -0.2, 0)):
    shadow = (mobject.copy()
              .set_fill(color, opacity=opacity)
              .set_stroke(width=0)
              .shift(shift)
              .set_z_index(-1)
              )
    mobject.add(shadow)
    return mobject

config.background_color = WHITE

class Test(Scene): 
    def construct(self):
        card = Rectangle(height=3, width=4.5, fill_opacity=1, fill_color=WHITE, stroke_color=BLACK)
        circle = Circle(radius=1, fill_opacity=1, fill_color=WHITE, stroke_color=RED).to_corner(UL)
        star = Star(n=5, fill_opacity=1, fill_color=WHITE, stroke_color=BLUE).next_to(circle, RIGHT)
        add_shadow(card)
        add_shadow(circle)
        add_shadow(star)
        self.add(card, circle, star)

image

uwezi avatar Feb 07 '24 22:02 uwezi

There is also another message on Discord by a user who claims that he has developed a drop-shadow in Manim back in 2022, but he seems to have never shared his code: https://discord.com/channels/581738731934056449/581738732646957057/958273360612192256

uwezi avatar Feb 07 '24 22:02 uwezi