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