Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Option to scale stroke_width #3525

Closed
hyranno opened this issue Dec 13, 2023 · 3 comments · Fixed by #3965
Closed

Option to scale stroke_width #3525

hyranno opened this issue Dec 13, 2023 · 3 comments · Fixed by #3965
Labels
new feature Enhancement specifically adding a new feature (feature request should be used for issues instead)

Comments

@hyranno
Copy link

hyranno commented Dec 13, 2023

Description of proposed feature

Add option to mobject.scale to scale including vmobject.stroke_width.
mobject.scale just changes its points, does not touch stroke_width for now.
But sometime I want to scale them including stroke_width, to preserve the appearance.

How can the new feature be used?

mobject.scale(scale_factor, scale_stroke_width=True)

Additional comments

I expect code like below, but no sure while I'm new to python and manim.

def family_members_with_stroke_width(self) -> list[Self]:
    return [m for m in self.get_family() if  m.get_stroke_width && m.get_stroke_width() > 0]
def scale(self, scale_factor: float, scale_stroke_width=False, **kwargs) -> Self:
    if scale_stroke_width :
        for mob in self.family_members_with_stroke_width():
            mob.set_stroke(width=scale_factor * mob.get_stroke_width())
            mob.set_stroke(width=scale_factor * mob.get_stroke_width(background=True), background=True)
    self.apply_points_function_about_point(
        lambda points: scale_factor * points, **kwargs
    )
    return self
@hyranno hyranno added the new feature Enhancement specifically adding a new feature (feature request should be used for issues instead) label Dec 13, 2023
@github-project-automation github-project-automation bot moved this to 🆕 New in Dev Board Dec 13, 2023
@SORVER
Copy link

SORVER commented May 4, 2024

Can you explain more or show a video?

@hyranno
Copy link
Author

hyranno commented May 4, 2024

image
Think scaling the circle at the center.
mobject.scale(4) results the right, breaking the propotion of stroke to fill.
To result the left which preserve the propotion, its stroke_width should be scaled too.

@Boris-Filin
Copy link
Contributor

Hello there!
I have tested an implementation of your idea, I think I got it to work.
In short, the set_stroke is only called once instead of iterating over the family members, because the function itself is recursive.
There are some other modifications, like calculating the absolute value of the resulting stroke, because otherwise negative scaling removes the outline entirely.

Here is how the result looks:
Screenshot 2024-10-18 205521

Both text objects have an outline of 3px, and all circles were instantiated with outline of 100px, but the middle one is scaled to 25%.

Could you please assign me the issue when you have a moment?
We need the OSs contribution for university -_-

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new feature Enhancement specifically adding a new feature (feature request should be used for issues instead)
Projects
Status: 🆕 New
3 participants