2018-03-30 18:19:23 -07:00
|
|
|
import numpy as np
|
2018-03-31 15:11:35 -07:00
|
|
|
|
2018-03-30 18:19:23 -07:00
|
|
|
from PIL import Image
|
2018-12-24 12:37:51 -08:00
|
|
|
|
2019-01-24 22:24:01 -08:00
|
|
|
from manimlib.utils.file_ops import seek_full_path_from_defaults
|
2021-01-02 20:47:51 -08:00
|
|
|
from manimlib.utils.directories import get_raster_image_dir
|
|
|
|
from manimlib.utils.directories import get_vector_image_dir
|
2018-03-30 18:19:23 -07:00
|
|
|
|
2018-04-06 13:58:59 -07:00
|
|
|
|
2018-03-30 18:19:23 -07:00
|
|
|
def get_full_raster_image_path(image_file_name):
|
2019-01-24 22:24:01 -08:00
|
|
|
return seek_full_path_from_defaults(
|
2018-03-30 18:19:23 -07:00
|
|
|
image_file_name,
|
2021-01-02 20:47:51 -08:00
|
|
|
default_dir=get_raster_image_dir(),
|
2019-01-24 22:24:01 -08:00
|
|
|
extensions=[".jpg", ".png", ".gif"]
|
|
|
|
)
|
2018-04-06 13:58:59 -07:00
|
|
|
|
2018-03-30 18:19:23 -07:00
|
|
|
|
2021-01-02 20:47:51 -08:00
|
|
|
def get_full_vector_image_path(image_file_name):
|
|
|
|
return seek_full_path_from_defaults(
|
|
|
|
image_file_name,
|
|
|
|
default_dir=get_vector_image_dir(),
|
|
|
|
extensions=[".svg", ".xdv"],
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2018-03-30 18:19:23 -07:00
|
|
|
def drag_pixels(frames):
|
|
|
|
curr = frames[0]
|
|
|
|
new_frames = []
|
|
|
|
for frame in frames:
|
|
|
|
curr += (curr == 0) * np.array(frame)
|
|
|
|
new_frames.append(np.array(curr))
|
|
|
|
return new_frames
|
|
|
|
|
2018-04-06 13:58:59 -07:00
|
|
|
|
2018-03-30 18:19:23 -07:00
|
|
|
def invert_image(image):
|
|
|
|
arr = np.array(image)
|
|
|
|
arr = (255 * np.ones(arr.shape)).astype(arr.dtype) - arr
|
2018-04-06 13:58:59 -07:00
|
|
|
return Image.fromarray(arr)
|