mirror of
https://github.com/3b1b/manim.git
synced 2025-07-30 05:24:22 +08:00
Displahying with thickness is finally fast
This commit is contained in:
23
displayer.py
23
displayer.py
@ -60,8 +60,8 @@ def paint_mobjects(mobjects, image_array = None):
|
||||
)
|
||||
|
||||
flattener = np.array([[1], [width]], dtype = 'int')
|
||||
indices = np.dot(points, flattener)
|
||||
pixels[indices[:,0]] = (255*rgbs).astype(int)
|
||||
indices = np.dot(points, flattener)[:,0]
|
||||
pixels[indices] = (255*rgbs).astype('uint8')
|
||||
|
||||
pixels = pixels.reshape((height, width, 3)).astype('uint8')
|
||||
return pixels
|
||||
@ -71,24 +71,21 @@ def add_thickness(pixel_indices, rgbs, thickness, width, height):
|
||||
Imagine dragging each pixel around like a paintbrush in
|
||||
a square of pixels tickness x thickness big surrounding it
|
||||
"""
|
||||
nudge_values = range(-thickness/2+1, thickness/2+1)
|
||||
original = np.array(pixel_indices)
|
||||
original_rgbs = np.array(rgbs)
|
||||
for x, y in it.product(nudge_values, nudge_values):
|
||||
if x == 0 and y == 0:
|
||||
continue
|
||||
pixel_indices = np.append(
|
||||
pixel_indices,
|
||||
original+[x, y],
|
||||
axis = 0
|
||||
)
|
||||
rgbs = np.append(rgbs, original_rgbs, axis = 0)
|
||||
for nudge in range(-thickness/2+1, thickness/2+1):
|
||||
for x, y in [[nudge, 0], [0, nudge]]:
|
||||
pixel_indices = np.append(
|
||||
pixel_indices,
|
||||
original+[x, y],
|
||||
axis = 0
|
||||
)
|
||||
rgbs = np.append(rgbs, original_rgbs, axis = 0)
|
||||
admissibles = (pixel_indices[:,0] >= 0) & \
|
||||
(pixel_indices[:,0] < width) & \
|
||||
(pixel_indices[:,1] >= 0) & \
|
||||
(pixel_indices[:,1] < height)
|
||||
return pixel_indices[admissibles], rgbs[admissibles]
|
||||
|
||||
|
||||
|
||||
def place_on_screen(points, rgbs, space_width, space_height):
|
||||
|
@ -21,7 +21,7 @@ class Mobject(object):
|
||||
#Number of numbers used to describe a point (3 for pos, 3 for normal vector)
|
||||
DEFAULT_CONFIG = {
|
||||
"color" : "white",
|
||||
"point_thickness" : 2,
|
||||
"point_thickness" : 4,
|
||||
"name" : None,
|
||||
}
|
||||
DIM = 3
|
||||
|
@ -165,9 +165,7 @@ class Scene(object):
|
||||
for animation in animations:
|
||||
animation.update((t-t0)/(t1 - t0))
|
||||
index = int(t/self.frame_duration)
|
||||
self.frames[index] = disp.paint_mobject(
|
||||
CompoundMobject(*moving_mobjects), self.frames[index]
|
||||
)
|
||||
self.frames[index] = disp.paint_mobjects(moving_mobjects, self.frames[index])
|
||||
for animation in animations:
|
||||
animation.clean_up()
|
||||
return self
|
||||
|
Reference in New Issue
Block a user