Skip to content

Preserve user-specified gradient order for VMobject.set_color #4227

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

bliyanto
Copy link

@bliyanto bliyanto commented Apr 23, 2025

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.

  • Deterministic start → end colour mapping for any list passed to set_color(...) or set_stroke(...).
  • Automatic curve subdivision when a multi-stop gradient is requested on objects with < 50 anchor points, preventing “banding”.
  • New regression tests (tests/test_gradient_order.py) to lock-in behaviour.
  • A minimal demo scene (gradient_demo.py) for manual visual inspection.

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

  • 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
Status: 🆕 New
Development

Successfully merging this pull request may close these issues.

1 participant