Skip to content

Added new feature of Radial gradient#4730

Open
GoThrones wants to merge 10 commits into
ManimCommunity:mainfrom
GoThrones:camera
Open

Added new feature of Radial gradient#4730
GoThrones wants to merge 10 commits into
ManimCommunity:mainfrom
GoThrones:camera

Conversation

@GoThrones
Copy link
Copy Markdown
Contributor

@GoThrones GoThrones commented May 13, 2026

Overview: What does this pull request change?

This PR adds a new feature of having Radial Gradient to any VMobject.

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

There was no such feature in Manim.

It may also be pertinent to see this PR that I had made about a month ago: #4664
The method therein adds the feature of Radial gradient in a different way.

The code changes of PR #4664 and current PR can both co-exist and serve different purpose.

This is the test code:

class testradialgradient1(Scene):
    def construct(self):
        circle = Circle(radius = 1).set_fill([PURE_YELLOW, GREEN], opacity=1,gradient_type="radial").set_stroke(opacity = 0)
        rect = Rectangle().set_fill([ORANGE, PURE_YELLOW], opacity = 1, gradient_type= "radial").set_stroke(opacity = 0)        
        rp = RegularPolygon(3).scale(1.3*circle.radius).set_fill([BLUE, RED], opacity = 1, gradient_type= "radial").set_stroke(opacity = 0)
        vg = VGroup(circle, rect, rp).arrange()
        self.add(vg)

Output is:
1


class testradialgradient2(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_fill([RED, PURE_YELLOW], gradient_type= "radial", start_radius = 1)
        self.add(dots)
        self.play(dots.animate.move_to(3*RIGHT))
        self.wait()

Output of this code:

testradialgradient2.mp4

class testradialgradient3(Scene):
    def construct(self):
        circle = Circle(radius = 1)
        circle.move_to(3*LEFT+1.5*DOWN)
        circle.set_fill([PURE_YELLOW, GREEN], opacity=1,gradient_type="radial").set_stroke(opacity = 0)
        rect = Rectangle()
        rect.move_to(1.5*UP+3*RIGHT).set_fill([ORANGE, PURE_YELLOW], opacity = 1, gradient_type= "radial").set_stroke(opacity = 0)
        self.play(*[GrowFromCenter(mob) for mob in (circle, rect)])
        self.wait()        
        rect.add_updater(lambda x, dt: x.shift(LEFT*dt))
        circle.add_updater(lambda x,dt: x.shift(RIGHT*dt))
        self.wait(6)

Output of this code:

testradialgradient3.mp4





<!-- Thank you again for contributing! Do not modify the lines below, they are for reviewers. -->
## 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