Skip to content

Refactor set_color_by_radial_gradient & set_submobject_colors_by_radial_gradient#4664

Open
GoThrones wants to merge 8 commits intoManimCommunity:mainfrom
GoThrones:refactor/sscbradial_gradient
Open

Refactor set_color_by_radial_gradient & set_submobject_colors_by_radial_gradient#4664
GoThrones wants to merge 8 commits intoManimCommunity:mainfrom
GoThrones:refactor/sscbradial_gradient

Conversation

@GoThrones
Copy link
Copy Markdown
Contributor

@GoThrones GoThrones commented Mar 30, 2026

Overview: What does this pull request change?

This PR changes 2 methods of mobject.py:
(1) set_colors_by_radial_gradient
(2) set_submobject_colors_by_radial_gradient
to include inner_radius and outer_radius.
This PR also writes docstring for the method set_colors_by_radial_gradient which was not there previosly.

Motivation and Explanation: Why and how do your changes improve the library?

In the main branch, in set_submobject_colors_by_radial_gradient, there was no provision to set the inner_radius from which the colouring will start, it was set to be centre of the mobject, which was not much helpful. In the PR, the default is the set to the mobject's centre, but the user can set an inner radius of choosing, from where to begin colouring radially outwards.

See the output:

This is code for and output from the main branch:

class RadialGradientDemo(Scene):
    def construct(self):
        dots = VGroup()

        for r in np.arange(0.25, 4, 0.5):
            for angle in np.linspace(0, TAU, 12, endpoint = False):
                dots.add(Dot(radius = max(0.05*r, 0.06)).move_to([r * np.cos(angle), r * np.sin(angle), 0]))

        dots.add(Dot(radius=0.05))
        radius = float(min(np.linalg.norm(dots.get_corner(UR) - dots.get_center()), 3.75))
        dots.set_colors_by_radial_gradient(
            inner_color = RED,
            outer_color = PURE_YELLOW,
            radius = radius
        )
        self.add(dots)

Output:
main

This is the code for and output from the PR branch:

class RadialGradientDemo(Scene):
    def construct(self):
        dots = VGroup()

        for r in np.arange(0.25, 4, 0.5):
            for angle in np.linspace(0, TAU, 12, endpoint = False):
                dots.add(Dot(radius = max(0.05*r, 0.06)).move_to([r * np.cos(angle), r * np.sin(angle), 0]))

        dots.add(Dot(radius=0.05))
        dots.set_colors_by_radial_gradient(
            inner_radius = 1.25,
            inner_color = RED,
            outer_color = PURE_YELLOW,
             
            
        )
        self.add(dots)

output when inner_radius = 1.25:
1

Output when inner_radius = 0.0:
2

Output when inner_radius = 1.5 and outer_radius = 2.75:
final

Links to added or changed documentation pages

Further Information and Comments

Reviewer Checklist

  • The PR title is descriptive enough for the changelog, and the PR is labeled correctly
  • If applicable: newly added non-private functions and classes have a docstring including a short summary and a PARAMETERS section
  • If applicable: newly added functions and classes are tested

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant