0

Here is a very simple function where I am trying to draw a circle with changing radius upon a gif image. I can successfully draw a static red circle with my test_clip function, but I need clues how to incorporate the make_frame(t) function in order to I can achieve the desired result: a circle with changing radius on a gif or video. I am using Gizeh module, here. Thank you.

import gizeh
import moviepy.editor as mpy
import numpy as np

W,H = 128,128 # width, height, in pixels
duration = 2 # duration of the clip, in seconds


def make_frame(t):
    surface = gizeh.Surface(W,H, bg_color=(255,255,255))
    radius = W*(1+ (t*(duration-t))**2 )/6
    circle = gizeh.circle(radius, xy = (W/2,H/2), fill=(1,0,0))
    circle.draw(surface)
    return surface.get_npimage()

clip = mpy.VideoClip(make_frame, duration=duration)
clip.write_gif('example1.gif',fps=15, opt="OptimizePlus", fuzz=10)


def test_clip(clip):

    w, h = clip.size

    def fl(im):

        surface = gizeh.Surface.from_image(im)
        circle = gizeh.circle(r=30, xy=[w/2,h/2], fill=(1,0,0))
        circle.draw(surface)
        return surface.get_npimage()

    return clip.fl_image(fl)

im = mpy.VideoFileClip("example10.gif")
cc = im.fx(test_clip)
cc.write_gif("test.gif")
Anay Bose
  • 880
  • 1
  • 14
  • 24

1 Answers1

0

If I'm understanding you correctly, excuse me if I don't, you want a circle that changing size. Maybe you could You could make the radius a for loop where you change the radius every 0.016 seconds (60 fps).

Hope it helps!

Reaction on comment: yes. If you stop increasing the radius at 0.5 seconds and start decreasing it again, you will have a nice loop of pulsating circle.

Ya boy
  • 103
  • 1
  • 8