Crop a group, an object... #2815
Replies: 3 comments 2 replies
-
One way I think you can do this by creating a mask type thing with the difference of two rectangles, one being the dimensions of the frame and the other being of the area you want cropped, and setting the fill color to the background color with full fill opacity. Though for multiple objects and related masks you'd have to fiddle around with the z_index and stuff I'd assume. from manim import *
class Masking(Scene):
def construct(self):
numplane = NumberPlane(fill_opacity=0.5)
self.add(numplane)
mask = Difference(
Rectangle(height=config.frame_height, width=config.frame_width), #whole frame
Rectangle(height=3,width=5), #cropped
stroke_opacity=0,
fill_color=BLACK,
fill_opacity=1
)
self.add(mask) |
Beta Was this translation helpful? Give feedback.
-
Thanks for this trick. It is what I was referring to as a workaround (thanks for writing this code, it's a quite clean way to do this workaround) as it gets trickier to use when we use multiples cropped objects (the mask of the second object will hide the first object, so we need to remove from it the mask of the first object). And also, it would not be able to handle movements going behind the object. |
Beta Was this translation helpful? Give feedback.
-
Any reasons this issue has been moved to discussion? It should be considered as a feature request as appropriate crop is not available. |
Beta Was this translation helpful? Give feedback.
-
Description of proposed feature
Sometimes, it may be useful to crop an object, because the object could be theoretically infinite and I may just want to display a part of it, with other animations or text around it. It would be cool to be able to apply it to a group for instance.
How can the new feature be used?
For instance, I'd like to try to draw the following thing:
If crop is allowed with an arbitrary path, then we could also crop rectangle images to circle, and much fun would be possible.
Possible workarounds
The only workaround I can think of would be to draw some squares around the image with the color of the background, but it is not perfect: first, it's tedious to write properly, especially when multiple groups must be cropped. Secondly, it will fail if we want to make an object pass behind the crop part, or if two cropped objects are too close to each others. I also tried Intersection, but without luck on groups.
Beta Was this translation helpful? Give feedback.
All reactions