3b1b / manim

Animation engine for explanatory math videos
MIT License
68.71k stars 6.1k forks source link

Text attribute t2c not working with slices since v1.6.0 #1874

Closed Tuxt closed 2 years ago

Tuxt commented 2 years ago

Describe the bug

The t2c attribute of Text does not work with slices. While it does work by specifying specific words.

Code:

from manimlib import *

class Colors(Scene):

    def construct(self):
        one_color = Text('hello', color=BLUE)
        one_color.shift(UP)
        self.play(FadeIn(one_color))

        two_colors = Text('goodbye', t2c={
            '[0:4]': '#cc00aa',
            '[4:7]': '#00bb44'
        })
        self.play(FadeIn(two_colors))

        other_colors = Text('Good bye', t2c={
            'Good': BLUE,
            'bye': RED
        })
        other_colors.shift(DOWN)
        self.play(FadeIn(other_colors))

Wrong display or Error traceback: While in version 1.5.1 the colors of all the texts are displayed correctly

https://user-images.githubusercontent.com/5247088/193715287-08ce5d1c-3885-4c34-9657-948aba65bee0.mp4

In versions 1.6.0 and 1.6.1 the central text appears in white

https://user-images.githubusercontent.com/5247088/193715373-bfed7ac0-f0f6-4cbb-a067-6b0afd21e347.mp4

Additional context

I'm using Windows 10. Tested on a conda environment using python 3.8.13 and 3.9.13.

YishiMichael commented 2 years ago

Hi there. In the later versions we support passing a two-tuple to specify substrings, rather than a slice-like string. This is done in order to eliminate possible ambiguity. For example, by directly replacing "[0:4]" with (0, 4) should make the code work.