|
1 | 1 | from manimlib.animation.animation import Animation |
| 2 | +from manimlib.animation.composition import Succession |
2 | 3 | from manimlib.mobject.types.vectorized_mobject import VMobject |
| 4 | +from manimlib.mobject.mobject import Group |
3 | 5 | from manimlib.utils.bezier import integer_interpolate |
4 | 6 | from manimlib.utils.config_ops import digest_config |
5 | 7 | from manimlib.utils.rate_functions import linear |
6 | 8 | from manimlib.utils.rate_functions import double_smooth |
7 | 9 | from manimlib.utils.rate_functions import smooth |
8 | 10 |
|
9 | 11 | import numpy as np |
| 12 | +import itertools as it |
10 | 13 |
|
11 | 14 |
|
12 | 15 | class ShowPartial(Animation): |
@@ -132,4 +135,42 @@ def __init__(self, group, **kwargs): |
132 | 135 | def interpolate_mobject(self, alpha): |
133 | 136 | n_submobs = len(self.all_submobs) |
134 | 137 | index = int(self.int_func(alpha * n_submobs)) |
| 138 | + self.update_submobject_list(index) |
| 139 | + |
| 140 | + def update_submobject_list(self, index): |
135 | 141 | self.mobject.submobjects = self.all_submobs[:index] |
| 142 | + |
| 143 | + |
| 144 | +class ShowSubmobjectsOneByOne(ShowIncreasingSubsets): |
| 145 | + def __init__(self, group, **kwargs): |
| 146 | + new_group = Group(*group) |
| 147 | + super().__init__(new_group, **kwargs) |
| 148 | + |
| 149 | + def update_submobject_list(self, index): |
| 150 | + # N = len(self.all_submobs) |
| 151 | + if index == 0: |
| 152 | + self.mobject.submobjects = [] |
| 153 | + else: |
| 154 | + self.mobject.submobjects = self.all_submobs[index - 1] |
| 155 | + |
| 156 | + |
| 157 | +# TODO, this is broken... |
| 158 | +class AddTextWordByWord(Succession): |
| 159 | + CONFIG = { |
| 160 | + # If given a value for run_time, it will |
| 161 | + # override the time_per_char |
| 162 | + "run_time": None, |
| 163 | + "time_per_char": 0.06, |
| 164 | + } |
| 165 | + |
| 166 | + def __init__(self, text_mobject, **kwargs): |
| 167 | + digest_config(self, kwargs) |
| 168 | + tpc = self.time_per_char |
| 169 | + anims = it.chain(*[ |
| 170 | + [ |
| 171 | + ShowIncreasingSubsets(word, run_time=tpc * len(word)), |
| 172 | + Animation(word, run_time=0.005 * len(word)**1.5), |
| 173 | + ] |
| 174 | + for word in text_mobject |
| 175 | + ]) |
| 176 | + super().__init__(*anims, **kwargs) |
0 commit comments