ManimCommunity / ManimCommunity/manim
[BUG] DashedLine computes num_dashes only once (on init)
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 40.9k
- Forks
- 3.1k
- Avg merge
- 3d 12h
- Merged PRs (30d)
- 25
Description
## Description of bug / unexpected behavior
I am animating a DashedLine, using `put_start_and_end_on()` in an updater. This stretches the dashes, making them inconsistent with other DashedLines, when the length changes.
## Expected behavior
I would like to have consistent dash geometries among all my dashed lines, so the number of dashes would have to be recomputed when I change the line length. I would be fine with calling an extra method in my updater, but right now the code in `__init__` does not lend itself to being copied into an updater.
## How to reproduce the issue
Code for reproducing the problem
```py
class MovingDots(Scene):
def construct(self):
d1,d2=Dot(color=BLUE),Dot(color=GREEN)
dg=VGroup(d1,d2).arrange(RIGHT,buff=1)
l1=DashedLine(d1.get_center(),d2.get_center()).set_color(RED)
x=ValueTracker(0)
y=ValueTracker(0)
d1.add_updater(lambda z: z.set_x(x.get_value()))
d2.add_updater(lambda z: z.set_y(y.get_value()))
l1.add_updater(lambda z: z.put_start_and_end_on(d1.get_center(),d2.get_center()))
self.add(d1,d2,l1)
self.play(x.animate.set_value(5))
self.play(y.animate.set_value(4))
self.wait()
```
## Additional media files
Images/GIFs
https://github.com/user-attachments/assets/5824562a-1064-49e3-bb2c-c50b57dfbbb9
## Additional comments
My DashedLine has a number of properties, making it less attractive to use .become than in the above example. But I am new to manim, so maybe I am overlooking something.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the DashedLine implementation and its put_start_and_end_on() behavior, then reproduce the issue with the MovingDots example in the report. Done means changing the line length recomputes the number of dashes so dash geometry stays consistent during animation.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- computer-graphics
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 55/100