Beispiel #1
0
    def ZoomOnBranch(self, branch, total_frames, reset_view=False, margin=20):

        d = self.d

        x0, y0, x1, y1 = std.d.viewBox

        n = self.tree & branch

        x0f, y0f, x1f, y1f = n.x_coor - margin, n.y_coor - margin, n.x_coor + margin, n.y_coor + margin

        x0s = (x0f - x0) / float(total_frames)
        y0s = (y0f - y0) / float(total_frames)
        x1s = (x1f - x1) / float(total_frames)
        y1s = (y1f - y1) / float(total_frames)

        def draw_frame(i):
            std.d.viewBox = (
                x0 + i * x0s,
                y0 + i * y0s,
                x1 + i * x1s,
                y1 + i * y1s,
            )

            return (d)

        with draw.animate_jupyter(draw_frame, delay=0.05) as anim:
            for i in range(total_frames):
                anim.draw_frame(i)

        if reset_view:
            std.d.viewBox = x0, y0, x1, y1
Beispiel #2
0
    def ZoomOnPoint(self, point, total_frames, reset_view=False):

        d = self.d

        x0, y0, x1, y1 = std.d.viewBox

        x0f, y0f, x1f, y1f = point

        x0s = (x0f - x0) / float(total_frames)
        y0s = (y0f - y0) / float(total_frames)
        x1s = (x1f - x1) / float(total_frames)
        y1s = (y1f - y1) / float(total_frames)

        def draw_frame(i):
            std.d.viewBox = (
                x0 + i * x0s,
                y0 + i * y0s,
                x1 + i * x1s,
                y1 + i * y1s,
            )

            return (d)

        with draw.animate_jupyter(draw_frame, delay=0.05) as anim:
            for i in range(total_frames):
                anim.draw_frame(i)

        if reset_view:
            std.d.viewBox = x0, y0, x1, y1
Beispiel #3
0
    def AnimateForward(self, url):

        total_frames = 200

        d = self.d
        p = draw.Rectangle(0,
                           0,
                           self.width,
                           self.height,
                           fill="black",
                           id="Square")
        d.append(p)

        def draw_frame(i):
            std.d.elements[-1].args["y"] += (self.height / total_frames)
            #d.setRenderSize(h=self.height)
            #d.saveSvg(url)
            return (d)

        with draw.animate_jupyter(draw_frame, delay=0.05) as anim:
            for i in range(total_frames):
                anim.draw_frame(i)
Beispiel #4
0
 def wrapper(func):
     if save == 'mp4':
         with draw.animate_video(
                 f'{name}.mp4',
                 draw_frame,
                 fps=fps,
                 jupyter=preview,
         ) as anim:
             state = AnimState(anim, fps=fps)
             func(state)
     elif save == 'gif' or save is True:
         with draw.animate_video(
                 f'{name}.gif',
                 draw_frame,
                 duration=1 / fps,
                 jupyter=preview,
         ) as anim:
             state = AnimState(anim, fps=fps)
             func(state)
     else:
         with draw.animate_jupyter(draw_frame, delay=1 / fps) as anim:
             state = AnimState(anim, fps=fps)
             func(state)
     return func
import drawSvg as draw


# Draw a frame of the animation
def draw_frame(t):
    d = draw.Drawing(2, 5.00, origin=(-1, -1.05))
    d.setRenderSize(h=150)
    d.append(draw.Rectangle(-4, -4, 8, 10, fill='white'))
    d.append(draw.Rectangle(-1, -1.00, 8, 1.05, fill='brown'))
    t = (t + 1) % 2 - 1
    y = 4 - t**2 * 4
    d.append(draw.Circle(0, y, 1, fill='lime'))
    return d


with draw.animate_jupyter(draw_frame, delay=0.10) as anim:
    # Or:
    #with draw.animate_video('example6.gif', draw_frame, duration=0.05
    #                       ) as anim:
    # Add each frame to the animation
    for i in range(40):
        anim.draw_frame(i / 10)
    for i in range(40):
        anim.draw_frame(i / 10)
    for i in range(40):
        anim.draw_frame(i / 10)