Пример #1
0
def make_frame(t):
    surface = gz.Surface(W, H, bg_color=(1, 1, 1))

    gradient = gz.ColorGradient(type="radial",
                                stops_colors=[(0, (1, 0, 0, alpha)),
                                              (1, (0.9, 0, 0, alpha))],
                                xy1=[0.3, -0.3],
                                xy2=[0, 0],
                                xy3=[0, 1.4])
    for i in range(numBalls):
        if (t < duration / 2):
            newRadius = pytweening.easeInOutBounce(2 * t / duration) * radius
            newCircleRadius = pytweening.easeInOutBounce(
                2 * t / duration) * circleRadius
        else:
            newRadius = pytweening.easeInOutBounce(1 - (t / duration)) * radius
            newCircleRadius = pytweening.easeInOutBounce(
                1 - (t / duration)) * circleRadius

        angle = (2 * np.pi / numBalls) * i
        #center = (W/2) + gz.polar2cart(newCircleRadius, angle)
        center = (W / 2) + gz.polar2cart(circleRadius, angle)

        #ball = gz.circle(r=newRadius, fill=gradient).translate((x, y))
        ball = gz.circle(r=newRadius, fill=gradient).translate(center)
        ball.draw(surface)

    return surface.get_npimage()
Пример #2
0
def animation4(t):

    W = H = 480
    WSQ = W/4 
    a = np.pi/8 
    points = [(0,0),(1,0),(1-np.cos(a)**2,np.sin(2*a)/2),(0,0)]
    surface = gz.Surface(W,H)
    for k, (c1,c2) in enumerate([[(.7,0.05,0.05),(1,0.5,0.5)],
                                [(0.05,0.05,.7),(0.5,0.5,1)]]):

        grad = gz.ColorGradient("linear",xy1=(0,0), xy2 = (1,0),
                               stops_colors= [(0,c1),(1,c2)])
        r = min(np.pi/2,max(0,np.pi*(t-DURATION/3)/DURATION))
        triangle = gz.polyline(points,xy=(-0.5,0.5), fill=grad,
                        angle=r, stroke=(1,1,1), stroke_width=.02)
        square = gz.Group([triangle.rotate(i*np.pi/2)
                              for i in range(4)])
        squares = (gz.Group([square.translate((2*i+j+k,j))
                            for i in range(-3,4)
                            for j in range(-3,4)])
                   .scale(WSQ)
                   .translate((W/2-WSQ*t/DURATION,H/2)))

        squares.draw(surface)

    return surface.get_npimage()
Пример #3
0
def make_frame(t):
    surface = gz.Surface(W,H)
    for r,color, center in zip(radii, colors, centers):
        angle = 2*np.pi*(t/D*np.sign(color[0]-.5)+color[1])
        xy = center+gz.polar2cart(W/5,angle) # center of the ball
        gradient = gz.ColorGradient(type="radial",
                     stops_colors = [(0,color),(1,color/10)],
                     xy1=[0.3,-0.3], xy2=[0,0], xy3 = [0,1.4])
        ball = gz.circle(r=1, fill=gradient).scale(r).translate(xy)
        ball.draw(surface)
    return surface.get_npimage()
Пример #4
0
def make_ball(t, alpha):
    gradient = gz.ColorGradient(type="radial",
                                stops_colors=[(0, (1, 0, 0, alpha)),
                                              (1, (0.1, 0, 0, alpha))],
                                xy1=[0.3, -0.3],
                                xy2=[0, 0],
                                xy3=[0, 1.4])
    x = (-W / 3) + (5 * W / 3) * (t / D)
    y = ground - HJ * 4 * (x % DJ) * (DJ - (x % DJ)) / DJ**2
    coef = (HJ - y) / HJ
    ball = gz.circle(r=1, fill=gradient).scale(r).translate((x, y))
    return ball
Пример #5
0
def make_shadow(t):
    x = (-W / 3) + (5 * W / 3) * (t / D)
    y = ground - HJ * 4 * (x % DJ) * (DJ - (x % DJ)) / DJ**2
    coef = (HJ - y) / HJ
    shadow_gradient = gz.ColorGradient(type="radial",
                                       stops_colors=[(0, (0, 0, 0,
                                                          .2 - coef / 5)),
                                                     (1, (0, 0, 0, 0))],
                                       xy1=[0, 0],
                                       xy2=[0, 0],
                                       xy3=[0, 1.4])
    shadow = (gz.circle(r=(1 - coef / 4),
                        fill=shadow_gradient).scale(r, r / 2).translate(
                            (x, ground + r / 2)))
    return shadow
Пример #6
0
def animation2(t):

    W = H = 480
    nballs=60

    radii = np.random.randint(.1*W,.2*W, nballs)
    colors = np.random.rand(nballs,3)
    centers = np.random.randint(0,W, (nballs,2))

    surface = gz.Surface(W,H)
    for r,color, center in zip(radii, colors, centers):
        angle = 2*np.pi*(t/DURATION*np.sign(color[0]-.5)+color[1])
        xy = center+gz.polar2cart(W/5,angle)
        gradient = gz.ColorGradient(type="radial",
                     stops_colors = [(0,color),(1,color/10)],
                     xy1=[0.3,-0.3], xy2=[0,0], xy3 = [0,1.4])
        ball = gz.circle(r=1, fill=gradient).scale(r).translate(xy)
        ball.draw(surface)
    return surface.get_npimage()
Пример #7
0
def make_frame(t):

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

    gradient = gz.ColorGradient(type="radial",
                                stops_colors=[(0, (1, 0, 0, alpha)),
                                              (1, (0.1, 0, 0, alpha))],
                                xy1=[0.3, -0.3],
                                xy2=[0, 0],
                                xy3=[0, 1.4])
    for i in range(numStars):
        star = stars[i]
        star.x += star.vecX
        star.y += star.vecY
        ball = gz.circle(r=star.radius, fill=gradient).translate(
            (star.x, star.y))
        ball.draw(surface)
    return surface.get_npimage()
Пример #8
0
def make_frame(t):
    surface = gz.Surface(W, H, bg_color=(1, 1, 1))
    x = (-W / 3) + (5 * W / 3) * (t / D)
    y = ground - HJ * 4 * (x % DJ) * (DJ - (x % DJ)) / DJ**2
    coef = (HJ - y) / HJ
    shadow_gradient = gz.ColorGradient(type="radial",
                                       stops_colors=[(0, (0, 0, 0,
                                                          .2 - coef / 5)),
                                                     (1, (0, 0, 0, 0))],
                                       xy1=[0, 0],
                                       xy2=[0, 0],
                                       xy3=[0, 1.4])
    shadow = (gz.circle(r=(1 - coef / 4),
                        fill=shadow_gradient).scale(r, r / 2).translate(
                            (x, ground + r / 2)))
    shadow.draw(surface)
    ball = gz.circle(r=1, fill=gradient).scale(r).translate((x, y))
    ball.draw(surface)
    return surface.get_npimage()
"""

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

W, H = 200, 75
D = 3
r = 10
DJ, HJ = 50, 35
ground = 0.75 * H
outputdir = "./output/"

gradient = gz.ColorGradient(type = "radial",
                            stops_colors = [(0, (1, 0, 0)), (1, (0.1, 0, 0))],
                            xy1 = [0.3, -0.3],
                            xy2 = [0, 0],
                            xy3 = [0, 1.4])

def make_frame(t):
    surface = gz.Surface(W, H, bg_color = (1, 1, 1))
    x = (-W / 3) + (5 * W / 3) * (t / D)
    y = ground - HJ * 4 * (x % DJ) * (DJ - (x % DJ)) / DJ ** 2
    coef = (HJ - y) / HJ
    shadow_gradient = gz.ColorGradient(type = "radial",
                                       stops_colors = [(0, (0, 0, 0, 0.2 - coef / 5)),
                                                         (1, (0, 0, 0, 0))],
                                       xy1 = [0, 0],
                                       xy2 = [0, 0],
                                       xy3 = [0, 1.4])
    shadow = gz.circle(r = (1 - coef / 4),
Пример #10
0
surface = gz.Surface(L, L, bg_color=(1, 1, 1))

# DRAW THE TEXT

txt = gz.text("Gizeh",
              fontfamily="Dancing Script",
              fontsize=120,
              fill=(0, 0, 0),
              xy=(L / 2, L / 9))
txt.draw(surface)

# MAKE THE FIRST TRIANGLE

gradient = gz.ColorGradient('radial', [(0, (.3, .2, .8)), (1, (.4, .6, .8))],
                            xy1=(0, 0),
                            xy2=(0, r / 3),
                            xy3=(0, r))

triangle = gz.regular_polygon(r,
                              n=3,
                              fill=gradient,
                              stroke=(0, 0, 0),
                              stroke_width=3,
                              xy=(r, 0))

# BUILD THE FRACTAL RECURSIVELY

fractal = gz.Group([triangle.rotate(a) for a in angles])
for i in range(6):
    fractal = gz.Group([
        fractal.scale(.5).rotate(-np.pi).translate(
Пример #11
0
    def _update_voronoi_lines(self, baseframe):
        """
        update the current "alive" voronoi lines and their transparency and draw them to the input frame
        :param baseframe: frame on which the voronoi lines will be drawn
        """

        # def apply_alternating_color(color, t, opts):
        #     color = np.array(color)
        #     y = opts['offset'] + opts['ampl'] * (1 + math.sin(opts['freq'] * t)) / 2
        #     color = y * color
        #     if opts['clip']:
        #         color = np.clip(color, 0, 1)
        #     return tuple(color)

        # go through all the current sets of voronoi lines, construct the a-b-lines for the input frame,
        # set the color and draw the lines
        tmp_vor_lines = []
        for lines, lines_alpha, lines_alpha_decay in self.vor_lines:
            for a, b in lines:
                # restrict end points to current frame size
                a, b = restrict_line(a, b, baseframe.shape[1] - 1,
                                     baseframe.shape[0] - 1)
                a, b = map(np.array, (a, b))
                a[np.isnan(a)] = baseframe.shape[1] - 1
                b[np.isnan(b)] = baseframe.shape[0] - 1
                ax, ay = map(int, map(round, a))
                bx, by = map(int, map(round, b))
                a = (ax, ay)
                b = (bx, by)

                # get the color setting
                color = self.cur_scene['voronoi'].get('color', None)
                # alternating_color_opts = self.cur_scene['voronoi'].get('alternating_color', None)
                if color:  # add current alpha value for solid color
                    # if alternating_color_opts:
                    #     color = apply_alternating_color(color, self.clip_t, alternating_color_opts)

                    stroke = color + (lines_alpha, )
                else:  # make a color gradient between the pixels at the respective end points of the line
                    pix_a = tuple(baseframe[ay, ax, :] / 255)
                    pix_b = tuple(baseframe[by, bx, :] / 255)
                    # if alternating_color_opts:
                    #     pix_a = apply_alternating_color(pix_a, self.clip_t, alternating_color_opts)
                    #     pix_b = apply_alternating_color(pix_b, self.clip_t, alternating_color_opts)
                    # else:
                    #     pix_a = tuple(pix_a)
                    #     pix_b = tuple(pix_b)

                    pix_a = pix_a + (lines_alpha, )
                    pix_b = pix_b + (lines_alpha, )
                    stroke = gz.ColorGradient('linear',
                                              ((0, pix_a), (1, pix_b)), a, b)

                # draw the lines
                draw_lines(self.ctx, [(a, b)],
                           stroke,
                           stroke_width=STROKE_WIDTH)

            # decrease line transparency
            lines_alpha -= lines_alpha_decay

            # only retain lines that are visible (i.e. transparency above 0)
            if lines_alpha > 0:
                tmp_vor_lines.append((lines, lines_alpha, lines_alpha_decay))

        # retain lines for next frame
        self.vor_lines = tmp_vor_lines
Пример #12
0
import numpy as np
import gizeh as gz
import moviepy.editor as mpy

W, H = 300, 75
D = 2  # duration in seconds
r = 22  # size of the letters / pentagons

gradient = gz.ColorGradient("linear", ((0, (0, .5, 1)), (1, (0, 1, 1))),
                            xy1=(0, -r),
                            xy2=(0, r))
polygon = gz.regular_polygon(r, 5, stroke_width=3, fill=gradient)


def make_frame(t):
    surface = gz.Surface(W, H, bg_color=(1, 1, 1))
    for i, letter in enumerate("GIZEH"):
        angle = max(0, min(1, 2 * t / D - 1.0 * i / 5)) * 2 * np.pi
        txt = gz.text(letter, "Amiri", 3 * r / 2, fontweight='bold')
        group = (gz.Group([polygon, txt]).rotate(angle).translate(
            (W * (i + 1) / 6, H / 2)))
        group.draw(surface)
    return surface.get_npimage()


clip = mpy.VideoClip(make_frame, duration=D)
clip.write_gif("gifs/example6.gif", fps=20, opt="OptimizePlus")