mirror of
https://github.com/3b1b/manim.git
synced 2025-08-31 23:58:32 +00:00
Direct computation of color hex to speed things up
This commit is contained in:
parent
d35ba7b196
commit
983a3e0357
3 changed files with 28 additions and 14 deletions
|
@ -241,14 +241,22 @@ class Camera(object):
|
|||
canvas.symbol((0, 0), symbol, pen, fill)
|
||||
|
||||
def get_pen_and_fill(self, vmobject):
|
||||
pen = aggdraw.Pen(
|
||||
self.color_to_hex_l(self.get_stroke_color(vmobject)),
|
||||
max(vmobject.stroke_width, 0)
|
||||
)
|
||||
fill = aggdraw.Brush(
|
||||
self.color_to_hex_l(self.get_fill_color(vmobject)),
|
||||
opacity = int(self.color_max_val*vmobject.get_fill_opacity())
|
||||
)
|
||||
stroke_width = max(vmobject.get_stroke_width(), 0)
|
||||
if stroke_width == 0:
|
||||
pen = None
|
||||
else:
|
||||
stroke_rgb = self.get_stroke_rgb(vmobject)
|
||||
stroke_hex = rgb_to_hex(stroke_rgb)
|
||||
pen = aggdraw.Pen(stroke_hex, stroke_width)
|
||||
|
||||
fill_opacity = int(self.color_max_val*vmobject.get_fill_opacity())
|
||||
if fill_opacity == 0:
|
||||
fill = None
|
||||
else:
|
||||
fill_rgb = self.get_fill_rgb(vmobject)
|
||||
fill_hex = rgb_to_hex(fill_rgb)
|
||||
fill = aggdraw.Brush(fill_hex, fill_opacity)
|
||||
|
||||
return (pen, fill)
|
||||
|
||||
def color_to_hex_l(self, color):
|
||||
|
@ -257,14 +265,14 @@ class Camera(object):
|
|||
except:
|
||||
return Color(BLACK).get_hex_l()
|
||||
|
||||
def get_stroke_color(self, vmobject):
|
||||
return vmobject.get_stroke_color()
|
||||
def get_stroke_rgb(self, vmobject):
|
||||
return vmobject.get_stroke_rgb()
|
||||
|
||||
def get_fill_color(self, vmobject):
|
||||
return vmobject.get_fill_color()
|
||||
def get_fill_rgb(self, vmobject):
|
||||
return vmobject.get_fill_rgb()
|
||||
|
||||
def get_pathstring(self, vmobject):
|
||||
result = ""
|
||||
result = ""
|
||||
for mob in [vmobject]+vmobject.get_subpath_mobjects():
|
||||
points = mob.points
|
||||
# points = self.adjust_out_of_range_points(points)
|
||||
|
|
|
@ -126,7 +126,7 @@ def rgba_to_color(rgba):
|
|||
return rgb_to_color(rgba[:3])
|
||||
|
||||
def rgb_to_hex(rgb):
|
||||
return Color(rgb = rgb).get_hex_l()
|
||||
return "#" + "".join('%02x'%int(255*x) for x in rgb)
|
||||
|
||||
def invert_color(color):
|
||||
return rgb_to_color(1.0 - color_to_rgb(color))
|
||||
|
|
|
@ -120,6 +120,9 @@ class VMobject(Mobject):
|
|||
)
|
||||
return self
|
||||
|
||||
def get_fill_rgb(self):
|
||||
return self.fill_rgb
|
||||
|
||||
def get_fill_color(self):
|
||||
try:
|
||||
self.fill_rgb = np.clip(self.fill_rgb, 0.0, 1.0)
|
||||
|
@ -130,6 +133,9 @@ class VMobject(Mobject):
|
|||
def get_fill_opacity(self):
|
||||
return np.clip(self.fill_opacity, 0, 1)
|
||||
|
||||
def get_stroke_rgb(self):
|
||||
return self.stroke_rgb
|
||||
|
||||
def get_stroke_color(self):
|
||||
try:
|
||||
self.stroke_rgb = np.clip(self.stroke_rgb, 0, 1)
|
||||
|
|
Loading…
Add table
Reference in a new issue