@@ -189,6 +189,7 @@ def __init__(
189189 )
190190 if self .invert :
191191 self .pixel_array [:, :, :3 ] = 255 - self .pixel_array [:, :, :3 ]
192+ self .orig_alpha_pixel_array = self .pixel_array [:, :, 3 ].copy ()
192193 super ().__init__ (scale_to_resolution , ** kwargs )
193194
194195 def get_pixel_array (self ):
@@ -199,7 +200,7 @@ def set_color(self, color, alpha=None, family=True):
199200 rgb = color_to_int_rgb (color )
200201 self .pixel_array [:, :, :3 ] = rgb
201202 if alpha is not None :
202- self .pixel_array [:, :, 3 ] = int (255 * alpha )
203+ self .pixel_array [:, :, 3 ] = int (self . orig_alpha_pixel_array * alpha )
203204 for submob in self .submobjects :
204205 submob .set_color (color , alpha , family )
205206 self .color = color
@@ -214,7 +215,7 @@ def set_opacity(self, alpha):
214215 The alpha value of the object, 1 being opaque and 0 being
215216 transparent.
216217 """
217- self .pixel_array [:, :, 3 ] = int ( 255 * alpha )
218+ self .pixel_array [:, :, 3 ] = ( self . orig_alpha_pixel_array * alpha ). astype ( int )
218219 self .fill_opacity = alpha
219220 self .stroke_opacity = alpha
220221 return self
0 commit comments