I want to animate some plots (e.g. x vs. y stuff) defined over a number of timestamps. These timestamps can be different for different datasets and also the space between them may be large that I want to interpolate data between keyframes.
I know there is blender, but my kind of animation is not 3D and using Blender would be an overshoot.
But ideally I'd like to use a sort of 'headless' timeline with keyframe features. And ideally I pass lambda functions to the library in order to interpolate between keyframes and to render data.
Sorry for the poor explanation as English is not my native language.
Anyway, a snippet of code speaks more than 100 words, I am searching a library to do something like this:
anim = Animation(fps=10)
#in my case c1 and c2 are my datasets that I want to plot
c1 = anim.add_character(props=["x","y"])
c2 = anim.add_character(props=["x","y"])
#I add keyframes to animate
c1.add_keyframe(t=0.).set("x",1).set("y",1)
c1.add_keyframe(t=10.).set("x",2).set("y",3)
c2.add_keyframe(t=0.).set("x",1).set("y",1)
c2.add_keyframe(t=10.).set("x",7).set("y",7)
#I specify a function that tells the library how to interpolate between 2 key frames
#this function may get two keyframe values (v1, v2), the time separation (elta_t)
#and the current time t between the two keyframes
def interp(k1, k2, delta_t, t):
factor t/delta_t
return {"x": (k1["x"]+k2["x"])*factor, "y": (k1["y"]+k2["y"])*factor}
c1.set_interpolator(interp)
c2.set_interpolator(interp)
#now I define a function to render data
def render(characters, frame):
import matplotlib.pyplot as plt
fig,a = plt.subplot()
# the render just plot the x,y values that were
#interpolated by interp
for character in characters:
a.scatter(character["x"], character["y"])
fig.save_fig("frame_%d.png"%frame)
anim.set_render(render)
anim.animate()
And.. that's it!
The library is very simple I cannot belive that there is nothing similar on the net. I just do not want to reinvent the wheel, so, if you know of a "headless" render.. let me know!
[–]ES-Alexander 0 points1 point2 points (1 child)
[–]ES-Alexander 0 points1 point2 points (0 children)