Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # coding: utf-8
- # #MoviePy Demo
- # #### Import packages
- # In[1]:
- import gizeh
- from moviepy import editor as movie
- import numpy
- # #### Define parameters
- # In[ ]:
- width, height = 256, 256 # width, height, in pixels
- cx, cy = width/2, height/2 # center in pixels
- rmin, rmax = 50, 100 # minimum and maximum radius
- Pi = 3.14 # defining pi
- tmax = 2.0 # duration of the clip, in seconds
- freq = numpy.pi * 2 / tmax # pulsation frequency
- # #### Function to draw a single frame
- # In[ ]:
- def make_frame(t):
- # width, height
- surface = gizeh.Surface(width, height, bg_color=(0, 0, .3))
- # the diameter varies over time
- d = rmin + (rmax - rmin) * (1 + numpy.sin(t * freq)) / 2
- # the radius varies over time
- r = rmin + (rmax - rmin) * (1 + numpy.sin(t * freq/2)) / 2
- # let's draw something
- circle = gizeh.circle(d/4, xy = (cx, cy), fill=(1, 1, 1))
- circle.draw(surface)
- circle = gizeh.circle(d/5, xy = (cx, cy), fill=(1, 0, 0))
- circle.draw(surface)
- arc = gizeh.arc(r, a1=r*Pi*0.5, a2=r*Pi*0., xy = (cx, cy), stroke=(1,1,1), stroke_width= 15)
- arc.draw(surface)
- # returns a 8-bit RGB array
- return surface.get_npimage()
- # #### Create the clip
- # In[ ]:
- clip = movie.VideoClip(make_frame, duration=tmax)
- # #### Preview in the browser
- # In[ ]:
- clip.ipython_display(fps=20, autoplay=1, loop=4)
- # #### Create an animated GIF
- # In[ ]:
- rm -f "./output/animation.gif"
- # In[ ]:
- mkdir "output"
- # In[ ]:
- #output to the new one
- clip.write_gif("./output/animation.gif", fps=20)
- # [Download Image](./output/animation.gif)
- # In[ ]:
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement