Skip to content

Refactor color_gradient#4663

Open
GoThrones wants to merge 4 commits intoManimCommunity:mainfrom
GoThrones:refactor_color_gradient
Open

Refactor color_gradient#4663
GoThrones wants to merge 4 commits intoManimCommunity:mainfrom
GoThrones:refactor_color_gradient

Conversation

@GoThrones
Copy link
Copy Markdown
Contributor

@GoThrones GoThrones commented Mar 29, 2026

Overview: What does this pull request change?

This PR refactors the color_gradient method in core.py. It introduces two new parameters: transition_mode and blend_variation for the case when number_of_colors_provided = 1.

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

The code of color_gradient of main branch doesn't work as intended for the case when number of colors provided is 1. It returns back the same color, same brightness.

The PR makes it possible that when number of color provided is 1, then either the colors can be progressively lighter or darker as chosen, but the color itself will be of same hue. Also the brightness of successive colors can be varied using blend_variation. See the output below:

I used this code to test:

class trycolorgradient(Scene):
    def construct(self):
        #s = Text("India")
        sgroup = VGroup()
        colors = color_gradient([RED], 5)
        for i in range(len(colors)):
            sq = Square().set_color(colors[i])
            sgroup.add(sq)
        self.add(sgroup.arrange(RIGHT))

Here's the output of the main branch: All the squares have same colors and same brightness. That means no gradient at all. Since the method's name is color_gradient, the effect should have gradient.
main

Here's the output given by PR branch:
When transition_mode = "lighter". Each next square is lighter than the previous one.
PR lighter

When transition_mode = "darker". Each next square is darker than the previous one.
PR darker

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