FlowerΒΆ
This example uses the rotate() and morph() animations to animate a Circle, fill and plot plot objects.
First, we create the pistil of the flower using a Circle:
import diplotocus as dpl
import numpy as np
pistil = dpl.Circle((0,0),.5,fc="#ffd97d",zorder=3)
Then, we create the petals:
theta = np.linspace(0,2*np.pi,360)
r1 = 2-0.6*np.sin(-5*theta)
x1 = r1*np.cos(theta)
y1 = r1*np.sin(theta)
r2 = 2-1*np.sin(-5*theta)
x2 = r2*np.cos(theta)
y2 = r2*np.sin(theta)
petals = dpl.fill(x1,y1,fc="#ff9b85",zorder=2)
Next, we create the stem:
y = np.linspace(-5,0,100)
theta = (1+y/5)*15/180*np.pi
d = 5 + y
x3 = np.arctan( theta)*d
x4 = np.arctan(-theta)*d
stem = dpl.plot(x3,y,c='#60d394',lw=10,zorder=1)
And finally, we create our timeline, animate our plot objects and render the video:
tl = dpl.Timeline(xlim=(-5,5),ylim=(-5,5),noaxis=True,figsize=(7,7))
e = dpl.easeInOutQuad()
petals.rotate(start_angle=0,end_angle=360,center=(0,0),duration=120)
petals.morph(new_x=x2,new_y=y2,duration=60)
petals.morph(new_x=x1,new_y=y1,duration=60,delay=60)
stem.morph(new_x=x4,new_y=y,duration=60,easing=e)
stem.morph(new_x=x3,new_y=y,duration=60,easing=e,delay=60)
pistil.rotate(start_angle=-15,end_angle=15,center=(0,-5),duration=60,easing=e)
petals.rotate(start_angle=-15,end_angle=15,center=(0,-5),duration=60,easing=e)
pistil.rotate(start_angle=0 ,end_angle=-30,center=(0,-5),duration=60,easing=e,delay=60)
petals.rotate(start_angle=0 ,end_angle=-30,center=(0,-5),duration=60,easing=e,delay=60)
tl.animate((pistil,petals,stem))
tl.save_video('../../_static/examples/flower.mp4')