FlagΒΆ

This example uses the math() animation to animate the y1 and y2 properties of a fill_between() plot object.

import diplotocus as dpl
import numpy as np

tl = dpl.Timeline(xlim=(-0.1,1.6),ylim=(-1,1),noaxis=True,figsize=(7,7))

x = np.linspace(0,1.5,100)

f1 = dpl.fill_between(x=x  ,y1=0,y2=1,fc='k')
f2 = dpl.fill_between(x=x  ,y1=0,y2=1,fc='g')
f3 = dpl.fill_between(x=x/3,y1=0,y2=1,fc='r')
f1.math('y1',lambda t: np.sin((x  *2*np.pi)**0.5)*np.sin(t*2*np.pi-x/0.5)/3 + .33/2        ,60)
f1.math('y2',lambda t: np.sin((x  *2*np.pi)**0.5)*np.sin(t*2*np.pi-x/0.5)/3 +    .5        ,60)
f2.math('y1',lambda t: np.sin((x  *2*np.pi)**0.5)*np.sin(t*2*np.pi-x/0.5)/3 - .5           ,60)
f2.math('y2',lambda t: np.sin((x  *2*np.pi)**0.5)*np.sin(t*2*np.pi-x/0.5)/3 - .33/2        ,60)
f3.math('y1',lambda t:(np.sin((x/3*2*np.pi)**0.5)*np.sin(t*2*np.pi-x/1.5)/3 - .5*(1-x/1.5)),60)
f3.math('y2',lambda t:(np.sin((x/3*2*np.pi)**0.5)*np.sin(t*2*np.pi-x/1.5)/3 + .5*(1-x/1.5)),60)

tl.animate((f1,f2,f3))
tl.save_video('../../_static/examples/flag.mp4')