From 632819dd6dc547a37dc497d1d2f1a27e54d26737 Mon Sep 17 00:00:00 2001 From: Grant Sanderson Date: Thu, 29 Dec 2022 19:45:29 -0800 Subject: [PATCH] Show examples of indexing by substrings and regular expressions --- example_scenes.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/example_scenes.py b/example_scenes.py index f005cecf..f9268aae 100644 --- a/example_scenes.py +++ b/example_scenes.py @@ -193,11 +193,7 @@ class TexTransformExample(Scene): ), ) self.wait() - self.play( - TransformMatchingStrings( - lines[1].copy(), lines[2], - ), - ) + self.play(TransformMatchingStrings(lines[1].copy(), lines[2])) self.wait() self.play( TransformMatchingStrings( @@ -208,6 +204,17 @@ class TexTransformExample(Scene): ), ) self.wait(2) + + # You can also index into Tex mobject (or other StringMobjects) + # by substrings and regular expressions + top_equation = lines[0] + low_equation = lines[3] + + self.play(LaggedStartMap(FlashAround, low_equation["C"], lag_ratio=0.5)) + self.play(LaggedStartMap(FlashAround, low_equation["B"], lag_ratio=0.5)) + self.play(LaggedStartMap(FlashAround, top_equation[re.compile(r"\w\^2")])) + self.play(Indicate(low_equation[R"\sqrt"])) + self.wait() self.play(LaggedStartMap(FadeOut, lines, shift=2 * RIGHT)) # TransformMatchingShapes will try to line up all pieces of a