napari / napari-animation

A napari plugin for making animations
https://napari.github.io/napari-animation/
Other
74 stars 27 forks source link

Smooth easing function #151

Closed kolibril13 closed 1 year ago

kolibril13 commented 1 year ago

Manim has a really nice "smooth" rate function, that's also the one that is used in most 3b1b videos: https://github.com/ManimCommunity/manim/blob/daf23c9d1031b12d9c119b8f6b7e60727d7f9242/manim/utils/rate_functions.py#L149-L156

image

And it can also be used directly in napari_animation.

Would a "smooth" rate function be worth adding in the napari-animation easing function section ?https://github.com/napari/napari-animation/blob/d8bd60939fb844e564ca54a5481cd0e2a80f854c/napari_animation/easing.py#L230

from napari_animation import Animation
from napari_animation.easing import Easing
from manim import rate_functions 

animation = Animation(viewer)
viewer.camera.zoom = 0.1
animation.capture_keyframe(steps=30)
viewer.camera.zoom = 1.4
animation.capture_keyframe(steps=60, ease=rate_functions.smooth)

animation.capture_keyframe(steps=30)
jupyter_napari_animation(animation, canvas_only=True, fps=60)
kolibril13 commented 1 year ago

I've just plotted the current napari-animation rate-functions, there are some that already look similar to "smooth" from manim:

image

And btw., this above example was generated by GitHub copilot. For these repetitive tasks, that's quite a cool tool!

https://user-images.githubusercontent.com/44469195/222404485-a10580ef-ff4a-4956-b4e0-da737037343f.mov

CLICK HERE to see Code

Code ```py import matplotlib.pyplot as plt import numpy as np from napari_animation.easing import Easing x = np.linspace(0,1,1000) # now LINEAR plt.figure(figsize=(6, 2), dpi=80) plt.plot(x, Easing.LINEAR(x)) plt.title("Linear") # now QUADRATIC plt.figure(figsize=(6, 2), dpi=80) QUADRATIC = np.vectorize(Easing.QUADRATIC) plt.plot(x,QUADRATIC(x)) plt.title("Quadratic") # now CUBIC plt.figure(figsize=(6, 2), dpi=80) CUBIC = np.vectorize(Easing.CUBIC) plt.plot(x,CUBIC(x)) plt.title("Cubic") # now QUINTIC plt.figure(figsize=(6, 2), dpi=80) QUINTIC = np.vectorize(Easing.QUINTIC) plt.plot(x,QUINTIC(x)) plt.title("Quintic") # now SINE plt.figure(figsize=(6, 2), dpi=80) SINE = np.vectorize(Easing.SINE) plt.plot(x,SINE(x)) plt.title("Sine") # now CIRCULAR plt.figure(figsize=(6, 2), dpi=80) CIRCULAR = np.vectorize(Easing.CIRCULAR) plt.plot(x,CIRCULAR(x)) plt.title("Circular") # now EXPONENTIAL plt.figure(figsize=(6, 2), dpi=80) EXPONENTIAL = np.vectorize(Easing.EXPONENTIAL) plt.plot(x,EXPONENTIAL(x)) plt.title("Exponential") # now ELASTIC plt.figure(figsize=(6, 2), dpi=80) ELASTIC = np.vectorize(Easing.ELASTIC) plt.plot(x,ELASTIC(x)) plt.title("Elastic") # now BACK plt.figure(figsize=(6, 2), dpi=80) BACK = np.vectorize(Easing.BACK) plt.plot(x,BACK(x)) plt.title("Back") # now BOUNCE plt.figure(figsize=(6, 2), dpi=80) BOUNCE = np.vectorize(Easing.BOUNCE) plt.plot(x,BOUNCE(x)) plt.title("Bounce") ```

alisterburt commented 1 year ago

Hey @kolibril13 !

Do you think smooth is different enough from exponential to be worth adding? https://easings.net/#easeInOutExpo

Happy to accept a PR if so although it looks like the bounds of manim rate functions are 0/100 rather than 0/1 so it might need modifying

kolibril13 commented 1 year ago

Hey @alisterburt, you are right, they are quite similar, thanks for pointing me to that link! The manim bound functions are also in the limit 0/1, that means they can be used interchangeably :) E.g. this code runs properly:

from manim import rate_functions 
animation.capture_keyframe(steps=60, ease=rate_functions.smooth)

That in mind, I think it's not necessary to have the smooth rate function in the napari, and I will close this issue!

alisterburt commented 1 year ago

thanks! :)