Reframe Mobject, VMobject and SurfaceMobject with a data map

This commit is contained in:
Grant Sanderson
2021-01-11 10:57:23 -10:00
parent b3335c65fb
commit 9314dfd933
10 changed files with 276 additions and 428 deletions

View File

@ -74,8 +74,8 @@ def interpolate(start, end, alpha):
sys.exit(2)
def set_array_by_interpolation(arr, arr1, arr2, alpha):
arr[:] = interpolate(arr1, arr2, alpha)
def set_array_by_interpolation(arr, arr1, arr2, alpha, interp_func=interpolate):
arr[:] = interp_func(arr1, arr2, alpha)
return arr

View File

@ -80,15 +80,23 @@ def listify(obj):
return [obj]
def stretch_array_to_length(nparray, length):
# TODO, rename to "resize"?
def resize_array(nparray, length):
return np.resize(nparray, (length, *nparray.shape[1:]))
def resize_preserving_order(nparray, length):
if len(nparray) == 0:
return np.zeros((length, *nparray.shape[1:]))
if len(nparray) == length:
return nparray
indices = np.arange(length) * len(nparray) // length
return nparray[indices]
def stretch_array_to_length_with_interpolation(nparray, length):
curr_len = len(nparray)
cont_indices = np.linspace(0, curr_len - 1, length)
def resize_with_interpolation(nparray, length):
if len(nparray) == length:
return nparray
cont_indices = np.linspace(0, len(nparray) - 1, length)
return np.array([
(1 - a) * nparray[lh] + a * nparray[rh]
for ci in cont_indices