忽略循环中的某些元组

2021-05-16 08:13:48 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在生成一些元组中的动画帧,其中可能包含(0,0)值,我希望在使用moviepy生成帧时忽略这些值。xy在循环中包含以下内容。第一次和第二次迭代包含(0,0),其余包含浮点。我想忽略那些拥有(0,0)的迭代。可以用moviepy的make_frame(t)def完成吗?我需要一些建议。你知道吗

(0, 0)
(0, 0)
(82.5, 82.5)
(82.5, 82.5)
(108.28125, 108.28125)
(108.28125, 108.28125)

我收到以下错误:

Traceback (most recent call last):
  File "C:\vhosts\VIDEO_TWO_CLONE\vapory-examples-master\scene9.py", line 151, in <module>
    clip = VideoClip(make_frame, duration=5)
  File "C:\Anaconda64\lib\site-packages\moviepy\video\VideoClip.py", line 103, in __init__
    self.size = self.get_frame(0).shape[:2][::-1]
AttributeError: 'NoneType' object has no attribute 'shape'
Process terminated with an exit code of 1

以下是make_帧(t)的定义:

def make_frame(t):

    # PREPARE A DRAWING SURFACE
    surface = gizeh.Surface(width=W, height=H, bg_color=(0,0,0)) # in pixels

    p = PointAnimation((0,0), (110,110), tween=['easeOutElastic', 1, 0.2])

    xy = p.make_frame(t, 0.2, 1, 4, 5)

    if str(xy) == '(0,0)':
        circle = gizeh.circle(r=30, xy=xy, fill=(1,1,0))
        circle.draw(surface) # draw the circle on the surface
        return surface.get_npimage()


clip = VideoClip(make_frame, duration=5)
clip.write_gif("circle.gif", fps=25, fuzz=10)