Building an animation using Python Gizeh -


i able create simple diagram shapes , numbers. using following code:

import gizeh gz  w, h = 500, 300  surface = gz.surface(w,h, bg_color=(1,0.7,1))  in range(1,9):     rect = gz.rectangle(lx = 10, ly = 10, xy=(w/a,h/a), fill =(0,1,0.7))     rect.draw(surface)     txt = gz.text(str(a), fontfamily="dancing script", fontsize=15, fill=(0,0,0),xy=(w/a,h/a))     txt.draw(surface)  surface.ipython_display() 

i have created version using moviepy:

import numpy np import gizeh gz import moviepy.editor mpy  w, h = 500, 300 duration = 5 figpath = '/tmp/' fps = 1  def make_frame(t):      surface = gz.surface(w,h, bg_color=(1,1,1))      rect = gz.rectangle(lx = 10, ly = 10, xy=(w/(t+1),h/2), fill =(0,1,0.7))     rect.draw(surface)     txt = gz.text(str(t+1), fontfamily="dancing script", fontsize=15, fill=(0,0,0),xy=(w/(t+1),h/2))     txt.draw(surface)      return surface.get_npimage()  clip = mpy.videoclip(make_frame, duration=duration) clip.write_videofile(figpath + 'trax_0.mp4', fps=fps)  clip.ipython_display(fps=fps, width=w, autoplay=0, loop=0) 

i able create animated gif using time delay between each step of cycle.

#!/usr/bin/env python3  import numpy np import gizeh gz import moviepy.editor mpy  w,h = 128,128 # 128x128 pixel duration = 2  # 2 seconds ncircles = 20 # number of circles  def make_frame(t):      surface = gz.surface(w,h)      in range(ncircles):         angle = 2*np.pi*(1.0*i/ncircles+t/duration)         center = w*( 0.5+ gz.polar2cart(0.1,angle))         circle = gz.circle(r= w*(1.0-1.0*i/ncircles),                               xy= center, fill= (i%2,i%2,i%2))         circle.draw(surface)      return surface.get_npimage()  clip = mpy.videoclip(make_frame, duration=duration) clip.write_gif("circles.gif",fps=15, opt="optimizeplus", fuzz=10) 

enter image description here


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -