Skip to content

refactor/color_gradient#4662

Closed
GoThrones wants to merge 2 commits intoManimCommunity:mainfrom
GoThrones:refactor_color_gradientv2
Closed

refactor/color_gradient#4662
GoThrones wants to merge 2 commits intoManimCommunity:mainfrom
GoThrones:refactor_color_gradientv2

Conversation

@GoThrones
Copy link
Copy Markdown
Contributor

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:

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 in current main branch:
main

Here's the output given by the changed code of PR:
When transition_mode = "lighter"
PR lighter

Output by PR when transition_mode = "darker"
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

@GoThrones GoThrones closed this Mar 29, 2026
@GoThrones GoThrones deleted the refactor_color_gradientv2 branch March 29, 2026 14:09
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