mirror of
https://github.com/3b1b/manim.git
synced 2025-09-01 00:48:45 +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)
|
canvas.symbol((0, 0), symbol, pen, fill)
|
||||||
|
|
||||||
def get_pen_and_fill(self, vmobject):
|
def get_pen_and_fill(self, vmobject):
|
||||||
pen = aggdraw.Pen(
|
stroke_width = max(vmobject.get_stroke_width(), 0)
|
||||||
self.color_to_hex_l(self.get_stroke_color(vmobject)),
|
if stroke_width == 0:
|
||||||
max(vmobject.stroke_width, 0)
|
pen = None
|
||||||
)
|
else:
|
||||||
fill = aggdraw.Brush(
|
stroke_rgb = self.get_stroke_rgb(vmobject)
|
||||||
self.color_to_hex_l(self.get_fill_color(vmobject)),
|
stroke_hex = rgb_to_hex(stroke_rgb)
|
||||||
opacity = int(self.color_max_val*vmobject.get_fill_opacity())
|
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)
|
return (pen, fill)
|
||||||
|
|
||||||
def color_to_hex_l(self, color):
|
def color_to_hex_l(self, color):
|
||||||
|
@ -257,14 +265,14 @@ class Camera(object):
|
||||||
except:
|
except:
|
||||||
return Color(BLACK).get_hex_l()
|
return Color(BLACK).get_hex_l()
|
||||||
|
|
||||||
def get_stroke_color(self, vmobject):
|
def get_stroke_rgb(self, vmobject):
|
||||||
return vmobject.get_stroke_color()
|
return vmobject.get_stroke_rgb()
|
||||||
|
|
||||||
def get_fill_color(self, vmobject):
|
def get_fill_rgb(self, vmobject):
|
||||||
return vmobject.get_fill_color()
|
return vmobject.get_fill_rgb()
|
||||||
|
|
||||||
def get_pathstring(self, vmobject):
|
def get_pathstring(self, vmobject):
|
||||||
result = ""
|
result = ""
|
||||||
for mob in [vmobject]+vmobject.get_subpath_mobjects():
|
for mob in [vmobject]+vmobject.get_subpath_mobjects():
|
||||||
points = mob.points
|
points = mob.points
|
||||||
# points = self.adjust_out_of_range_points(points)
|
# points = self.adjust_out_of_range_points(points)
|
||||||
|
|
|
@ -126,7 +126,7 @@ def rgba_to_color(rgba):
|
||||||
return rgb_to_color(rgba[:3])
|
return rgb_to_color(rgba[:3])
|
||||||
|
|
||||||
def rgb_to_hex(rgb):
|
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):
|
def invert_color(color):
|
||||||
return rgb_to_color(1.0 - color_to_rgb(color))
|
return rgb_to_color(1.0 - color_to_rgb(color))
|
||||||
|
|
|
@ -120,6 +120,9 @@ class VMobject(Mobject):
|
||||||
)
|
)
|
||||||
return self
|
return self
|
||||||
|
|
||||||
|
def get_fill_rgb(self):
|
||||||
|
return self.fill_rgb
|
||||||
|
|
||||||
def get_fill_color(self):
|
def get_fill_color(self):
|
||||||
try:
|
try:
|
||||||
self.fill_rgb = np.clip(self.fill_rgb, 0.0, 1.0)
|
self.fill_rgb = np.clip(self.fill_rgb, 0.0, 1.0)
|
||||||
|
@ -130,6 +133,9 @@ class VMobject(Mobject):
|
||||||
def get_fill_opacity(self):
|
def get_fill_opacity(self):
|
||||||
return np.clip(self.fill_opacity, 0, 1)
|
return np.clip(self.fill_opacity, 0, 1)
|
||||||
|
|
||||||
|
def get_stroke_rgb(self):
|
||||||
|
return self.stroke_rgb
|
||||||
|
|
||||||
def get_stroke_color(self):
|
def get_stroke_color(self):
|
||||||
try:
|
try:
|
||||||
self.stroke_rgb = np.clip(self.stroke_rgb, 0, 1)
|
self.stroke_rgb = np.clip(self.stroke_rgb, 0, 1)
|
||||||
|
|
Loading…
Add table
Reference in a new issue