Preserve user-specified gradient order for VMobject.set_color #4227
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Overview: What does this pull request change?
This PR fixes incorrect gradient ordering on VMobject descendants (Issue #4198) and adds first-class support for multi-stop gradients on short or dashed lines.
Bug: multi-stop gradients sometimes appeared reversed or compressed when applied via set_color()/set_stroke() to Line, DashedLine, or other VMobjects.
Motivation and Explanation: Why and how do your changes improve the library?
Educators rely on gradients to indicate directionality; a flipped gradient can mislead viewers or hide content.
The root cause was that update_rgbas_array() relied on the existing RGBA buffer length, which for a newly-created Line is only four points (anchors+handles), far fewer than pixels rendered.
The patch:
1.Guarantees the internal RGBA buffer always has one row per point.
2. If the user supplies > 1 colour and the object has fewer than 50 points, we call insert_n_curves() to increase resolution before interpolating the gradient.
3. Uses the explicit colour list order to generate color_gradient, ensuring the first list element lands on the first point, last on the last point.
No public API is broken, single-colour strokes and fills behave exactly as before.
Links to added or changed documentation pages
manim/types/vectorized_mobject.py
Further Information and Comments
Reviewer Checklist