Exemplo n.º 1
0
 def align_rgbas(self, vmobject):
     attrs = ["fill_rgbas", "stroke_rgbas", "background_stroke_rgbas"]
     for attr in attrs:
         a1 = getattr(self, attr)
         a2 = getattr(vmobject, attr)
         if len(a1) > len(a2):
             new_a2 = stretch_array_to_length(a2, len(a1))
             setattr(vmobject, attr, new_a2)
         elif len(a2) > len(a1):
             new_a1 = stretch_array_to_length(a1, len(a2))
             setattr(self, attr, new_a1)
     return self
Exemplo n.º 2
0
 def align_rgbas(self, vmobject):
     attrs = ["fill_rgbas", "stroke_rgbas", "background_stroke_rgbas"]
     for attr in attrs:
         a1 = getattr(self, attr)
         a2 = getattr(vmobject, attr)
         if len(a1) > len(a2):
             new_a2 = stretch_array_to_length(a2, len(a1))
             setattr(vmobject, attr, new_a2)
         elif len(a2) > len(a1):
             new_a1 = stretch_array_to_length(a1, len(a2))
             setattr(self, attr, new_a1)
     return self
Exemplo n.º 3
0
 def align_points_with_larger(self, larger_mobject):
     assert(isinstance(larger_mobject, PMobject))
     self.apply_over_attr_arrays(
         lambda a: stretch_array_to_length(
             a, larger_mobject.get_num_points()
         )
     )
 def update_rgbas_array(self, array_name, color, opacity):
     rgbas = self.generate_rgba_array(color or BLACK, opacity or 0)
     # Match up current rgbas array with the newly calculated
     # one. 99% of the time they'll be the same.
     curr_rgbas = getattr(self, array_name)
     if len(curr_rgbas) < len(rgbas):
         curr_rgbas = stretch_array_to_length(curr_rgbas, len(rgbas))
         setattr(self, array_name, curr_rgbas)
     elif len(rgbas) < len(curr_rgbas):
         rgbas = stretch_array_to_length(rgbas, len(curr_rgbas))
     # Only update rgb if color was not None, and only
     # update alpha channel if opacity was passed in
     if color is not None:
         curr_rgbas[:, :3] = rgbas[:, :3]
     if opacity is not None:
         curr_rgbas[:, 3] = rgbas[:, 3]
     return self
Exemplo n.º 5
0
 def update_rgbas_array(self, array_name, color=None, opacity=None):
     passed_color = color if (color is not None) else BLACK
     passed_opacity = opacity if (opacity is not None) else 0
     rgbas = self.generate_rgbas_array(passed_color, passed_opacity)
     if not hasattr(self, array_name):
         setattr(self, array_name, rgbas)
         return self
     # Match up current rgbas array with the newly calculated
     # one. 99% of the time they'll be the same.
     curr_rgbas = getattr(self, array_name)
     if len(curr_rgbas) < len(rgbas):
         curr_rgbas = stretch_array_to_length(curr_rgbas, len(rgbas))
         setattr(self, array_name, curr_rgbas)
     elif len(rgbas) < len(curr_rgbas):
         rgbas = stretch_array_to_length(rgbas, len(curr_rgbas))
     # Only update rgb if color was not None, and only
     # update alpha channel if opacity was passed in
     if color is not None:
         curr_rgbas[:, :3] = rgbas[:, :3]
     if opacity is not None:
         curr_rgbas[:, 3] = rgbas[:, 3]
     return self
Exemplo n.º 6
0
 def update_rgbas_array(self, array_name, color=None, opacity=None):
     passed_color = color if (color is not None) else BLACK
     passed_opacity = opacity if (opacity is not None) else 0
     rgbas = self.generate_rgbas_array(passed_color, passed_opacity)
     if not hasattr(self, array_name):
         setattr(self, array_name, rgbas)
         return self
     # Match up current rgbas array with the newly calculated
     # one. 99% of the time they'll be the same.
     curr_rgbas = getattr(self, array_name)
     if len(curr_rgbas) < len(rgbas):
         curr_rgbas = stretch_array_to_length(
             curr_rgbas, len(rgbas)
         )
         setattr(self, array_name, curr_rgbas)
     elif len(rgbas) < len(curr_rgbas):
         rgbas = stretch_array_to_length(rgbas, len(curr_rgbas))
     # Only update rgb if color was not None, and only
     # update alpha channel if opacity was passed in
     if color is not None:
         curr_rgbas[:, :3] = rgbas[:, :3]
     if opacity is not None:
         curr_rgbas[:, 3] = rgbas[:, 3]
     return self
Exemplo n.º 7
0
 def align_points_with_larger(self, larger_mobject):
     assert (isinstance(larger_mobject, PMobject))
     self.apply_over_attr_arrays(lambda a: stretch_array_to_length(
         a, larger_mobject.get_num_points()))