gpt4 book ai didi

python - 使用 Python Gizeh 构建动画

转载 作者:太空狗 更新时间:2023-10-29 17:50:34 28 4
gpt4 key购买 nike

我能够创建一个包含形状和数字的简单图表。我正在使用以下代码:

import gizeh as gz

W, H = 500, 300

surface = gz.Surface(W,H, bg_color=(1,0.7,1))

for a 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()

我还使用 moviepy 创建了一个版本:

import numpy as np
import gizeh as gz
import moviepy.editor as 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)

我希望能够在循环的每个步骤之间使用时间延迟来创建动画 GIF。

最佳答案

尝试使用 MoviePy - 来自 Gizeh 作者的模块。
看一篇很好的文章,其中 Gizeh 和 MoviePy 用于动画: http://zulko.github.io/blog/2014/09/20/vector-animations-with-python/

关于python - 使用 Python Gizeh 构建动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30555150/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com