示例#1
0
文件: spiral.py 项目: wapu/animations
def make_frame(t):
    surface = gz.Surface(width, height)
    progress = t / duration

    cut = int(progress * len(points_p)) + 430
    points = np.concatenate(
        [points_[cut:], points_[:cut] + (0, 2 * np.pi * n_reps)])
    points[:, 1] -= 2 * np.pi * progress
    points[:, 1] *= stretch

    r_coefficients = np.power(points[:, 1] / (2 * np.pi * n_reps * stretch), 3)
    points[:, 0] *= r_coefficients

    mean_rs = r * r_coefficients
    points[:, 0] = (points[:, 0] - mean_rs) * stretch + mean_rs

    points[:, 0] *= 0.8
    points[:, 1] += 2 * np.pi * progress - 0.5 * np.pi
    points = polar_to_cartesian_np(points) + center

    surface = gz.Surface(width, height)
    n_segments = 50
    for i in range(10, n_segments):
        color = [1, 1, 1, ((i + 1) / n_segments)**2]
        gz.polyline(points=points[len(points) * i // n_segments:len(points) *
                                  (i + 1) // n_segments + 1],
                    stroke_width=2 * (i + 1) / n_segments,
                    stroke=color).draw(surface)

    return surface.get_npimage()
示例#2
0
    def make_frame(self, t):
        """
		Creates colored pointer. Background color is the blur color, pointer (rect) color is the color
		of the pointer.
		"""
        surface = gz.Surface(self.width,
                             self.height,
                             bg_color=self.p_glow_color)
        # rect = gz.rectangle(lx=150, ly=5, xy=(250,250), fill=(0,1,0), angle=3.1415926/(2*t+1))
        rect = gz.rectangle(
            lx=self.p_length,
            ly=self.p_width,
            xy=(self.p_rot_center_x + self.p_length * self.p_shift,
                self.p_rot_center_y),
            fill=self.p_color)
        rect = rect.rotate(self.speed2angle(t),
                           center=[self.p_rot_center_x, self.p_rot_center_y])
        rect.draw(surface)
        if self.g_text_visible:
            txt = gz.text('{0}'.format(
                int(self.gps_speed[int(t)] * self.unit_conversion_factor)),
                          fontfamily=self.g_text_fontFamily,
                          fontsize=self.g_text_size,
                          xy=(self.g_text_x, self.g_text_y),
                          fill=self.p_color)
            txt.draw(surface)
        arr = surface.get_npimage()
        if self.parent is not None:
            self.parent.processBarExport(p=1)
            if self.parent.cancelExport is True:
                raise TypeError('Canceling...')
        return arr
示例#3
0
def make_frame(t):
    surface = gz.Surface(width, height)
    progress = t / duration

    t_floaters = (progress * repetitions + progresses) % 1.0
    floaters = np.stack([
        x_shifts + amplitudes * np.sin(2 * np.pi * t_floaters *
                                       (height / periods)),
        50 + (width - 100) * (1 - t_floaters)
    ]).T
    d_center = np.sum(np.square(floaters - np.array([width / 2, height / 2])),
                      axis=1) - (width / 2)**2

    points = np.concatenate([symbol, floaters[d_center < 0, :]])

    d = distance_matrix(symbol, floaters)
    for i in range(len(symbol)):
        for j in range(len(floaters)):
            if d[i, j] <= max_dist:
                alpha = (1 - d[i, j] / max_dist)**2
                gz.polyline(points=[points[i, :], floaters[j, :]],
                            stroke=(1, 1, 1, alpha),
                            stroke_width=1).draw(surface)

    return surface.get_npimage()
示例#4
0
文件: movie.py 项目: felix0901/NEAT
    def make_frame(t):
        inputs = sim.get_scaled_state()
        if hasattr(net, 'activate'):
            action = net.activate_cpu(inputs)
            #action = net.activate(inputs)
            #action = net.my_activate(inputs)
        else:
            action = net.advance(inputs, sim.time_step, sim.time_step)

        sim.step(force_function(action))

        surface = gz.Surface(w, h, bg_color=(1, 1, 1))

        # Convert position to display units
        visX = scale * sim.x

        # Draw cart.
        group = gz.Group((cart, )).translate((visX, 0))
        group.draw(surface)

        # Draw pole.
        group = gz.Group((pole, )).translate(
            (visX, 0)).rotate(sim.theta, center=(150 + visX, 80))
        group.draw(surface)

        return surface.get_npimage()
示例#5
0
def draw_seconds(seconds):
    center = numpy.array([40 / 2, 16 / 2])

    surface = gizeh.Surface(width=40, height=16,
                            bg_color=(0, 0, 0))  # in pixels

    image = alpha_to_color(misc.imread('alpaka.png'))
    alpaka = gizeh.ImagePattern(image, pixel_zero=center)

    r = gizeh.rectangle(lx=40, ly=16, xy=(24, 8), fill=alpaka)
    r.draw(surface)

    text = gizeh.text("{:02d}".format(seconds),
                      fontfamily="DIN Condensed",
                      fontsize=20,
                      fill=(0.99, 0.82, 0.25),
                      xy=(32, 8),
                      angle=0)  # Pi/12)
    text.draw(surface)

    #surface.write_to_png("circle.png")
    out = surface.get_npimage()
    fb = out.tobytes()

    prepped = prepare_message(fb, unpack=False)
    send_array(prepped, '100.100.218.106')
示例#6
0
def render_text(t):
    surface = gz.Surface(640, 60, bg_color=WHITE_GIZEH)
    text = gz.text(
        "Let's build together", fontfamily="Charter",
        fontsize=30, fontweight='bold', fill=BLUE, xy=(320, 40))
    text.draw(surface)
    return surface.get_npimage()
示例#7
0
    def _make_frame_per_frame(self, ind):

        if isinstance(self._picture, BaseForm):
            surface = gizeh.Surface(int(self.screen_size[0] * 2), int(self.screen_size[1] * 2))
            self._picture.surface = surface

            for i in range(self.meta_multiplicity):

                for attr in ['center', 'angle']:
                    if hasattr(self._picture, attr):
                        attr_list = self.__getattribute__(attr + 's')
                        if not isinstance(attr_list, type(None)):
                            self._picture.__setattr__(attr, attr_list[i][ind])

                self._picture.draw(ind)

            return self._picture.surface.get_npimage(transparent=True)

        else:
            pic = None

            for i in range(self.meta_multiplicity):
                self._picture.center = self.centers[i][ind]
                newpic = Image.fromarray(self._picture._make_frame_per_frame(ind)).convert('RGBA')
                if pic:
                    pic.paste(newpic, (0, 0), newpic)
                else:
                    pic = newpic

            return np.array(pic.convert('RGBA'))
示例#8
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()
示例#9
0
def render_visual_state(state,
                        pixels_per_worldunit,
                        bg_color=(0.3, 0.3, 0.3),
                        scale_to_multiple_of_ten=True) -> np.ndarray:
    """
    Converts a 'visual state' to a rendered image

    :param state: dict with entries 'display_objects' (iterable of tuples (int, DisplayableObject)) and 'camera'
    :param pixels_per_worldunit: number of rendered pixels per world unit
    :param bg_color: background-color-tuple (r,g,b)
    :return: rendered image as 3D-numpy array
    """
    width, height = state['camera'].get_img_dims(pixels_per_worldunit)

    if bg_color is not None and len(bg_color) == 3:
        bg_color = bg_color + (1., )

    if scale_to_multiple_of_ten:
        surface_dims = (int(np.ceil(width / 10)) * 10,
                        int(np.ceil(height / 10)) * 10)
    else:
        surface_dims = (int(round(width)), int(round(height)))

    # Ensure that output image has dimensions as a multiple of 10 (video player compatibility)
    surface = gizeh.Surface(*surface_dims, bg_color)

    # The elements of state['display_objects'] have the drawing order as their first entry
    for _, display_object in sorted(state['display_objects'].values(),
                                    key=lambda t: t[0]):
        display_object.draw(surface, state['camera'], pixels_per_worldunit)

    img = surface.get_npimage()
    return img
def make_frame(t):
    dt = 1.0 * DURATION / 2 / NDISKS_PER_CYCLE
    N = int(NDISKS_PER_CYCLE / SPEED)
    t0 = 1.0 / SPEED

    surface = gz.Surface(W, H)
    for i in range(1, N):
        a = (np.pi / NDISKS_PER_CYCLE) * (N - i - 1)
        r = np.maximum(0, 0.05 * (t + t0 - dt * (N - i - 1)))
        center = W * (0.5 + gz.polar2cart(r, a))
        color = 1 * ((1.0 * i / NDISKS_PER_CYCLE) % 1.0, 1, 0)
        circle = gz.circle(r=0.3 * W,
                           xy=center,
                           fill=color,
                           stroke_width=0.01 * W)
        circle.draw(surface)

    contour1 = gz.circle(r=0.65 * W, xy=[W / 2, W / 2], stroke_width=0.5 * W)
    contour2 = gz.circle(r=0.42 * W,
                         xy=[W / 2, W / 2],
                         stroke_width=0.02 * W,
                         stroke=(1, 1, 1))
    contour1.draw(surface)
    contour2.draw(surface)
    return surface.get_npimage()
def half(t, side="left"):
    points = gz.geometry.polar_polygon(NFACES, R, NSQUARES)
    #ipoint = 0 if side=="left" else NSQUARES/2
    #points = (points[ipoint:]+points[:ipoint])[::-1]

    #for point in points:
    #  print point

    surface = gz.Surface(W, H)

    centerPoints = []
    for (r, th, d) in points:
        center = W * (0.5 + gz.polar2cart(r, th))
        angle = -(6 * np.pi * d + t * np.pi / DURATION)
        #color= colorsys.hls_to_rgb((2*d+t/DURATION)%1,.5,.5)
        centerPoints.append(center)
        color = (0.9, 0.9, 0.9)
        square = gz.circle(r=4.0, xy=center, fill=color)
        #square = gz.square(l=0.17*W, xy= center, angle=angle,
        #           fill=color, stroke_width= 0.005*W, stroke=(1,1,1))

        square.draw(surface)

    line = gz.polyline(points=centerPoints, stroke_width=1, stroke=(1, 0, 0))
    line.draw(surface)

    im = surface.get_npimage()
    return (im[:, :W / 2] if (side == "left") else im[:, W / 2:])
示例#12
0
def make_frame(t):
    
    W,H = np.array([box,box]) # width, height, in pixels
    radius = (box/256.0)*10
    surface = gizeh.Surface(W,H)

    i = int((t/duration)*pt_N)
    dx = np.array([W/2.,H/2.])
    pts = R[i]

    cx = np.sin(t/duration*(np.pi))
    c = (cx, 0.5, 0, alpha)
    
    for x,y in pts:
        xy = dx + [x,y]*dx/1.5

        scale = box/128.

        if use_circles:
            circle = gizeh.circle(radius+(2*scale), xy=xy, fill=[1,1,1,alpha])
            circle.draw(surface)

            circle = gizeh.circle(radius+(1*scale), xy=xy, fill=[0,0,0,1])
            circle.draw(surface)
        
        circle = gizeh.circle(radius, xy=xy, fill=c)
        circle.draw(surface)

    img = surface.get_npimage()
    return img 
示例#13
0
文件: spiral.py 项目: wapu/animations
def prepare():
    surface = gz.Surface(width, height)
    gz.rectangle(lx=width,
                 ly=height,
                 xy=(width / 2, height / 2),
                 fill=(0, 0, 0)).draw(surface)
    gz.circle(xy=(width / 2, height / 2), r=width / 2 - 10,
              fill=(1, 1, 1)).draw(surface)
    gz.circle(xy=(width / 2, height / 2), r=width / 2 - 40,
              fill=(0, 0, 0)).draw(surface)
    surface.write_to_png('spiral_ring.png')

    points = stipple_image_points('spiral_ring.png',
                                  n_points=5000,
                                  scale_factor=2,
                                  max_iterations=50)
    np.save('spiral_ring.npy', points)
    write_tsp('spiral_ring.tsp', points)

    run_linkern('spiral_ring.tsp', 'spiral_ring.cyc',
                '../../tools/linkern.exe')
    postprocess_cyc('spiral_ring.npy',
                    'spiral_ring.cyc',
                    'spiral_ring_processed.npy', (256, 256),
                    segment_length=5,
                    degree=3,
                    normalize_points=False)
示例#14
0
def prepare_data():
    surface = gz.Surface(1000, 1000)
    offset = np.array((500, 500))
    gz.square(l=1000, xy=offset, fill=(0, 0, 0)).draw(surface)

    radius, corners, stroke_width = get_extinction_symbol_params(400)
    gz.circle(r=radius, xy=offset, stroke=(1, 1, 1),
              stroke_width=stroke_width).draw(surface)
    gz.polyline(points=corners + offset,
                close_path=True,
                fill=None,
                stroke=(1, 1, 1),
                stroke_width=stroke_width).draw(surface)
    surface.write_to_png('extinction_symbol.png')

    print('STIPPLING EXTINCTION SYMBOL')
    points = stipple_image_points('extinction_symbol.png',
                                  n_points=2500,
                                  scale_factor=1,
                                  max_iterations=50)
    np.save('extinction_symbol', points)

    points = np.load('extinction_symbol.npy')
    write_tsp('extinction_symbol.tsp', points)
    run_linkern('extinction_symbol.tsp', 'extinction_symbol.cyc',
                '../../tools/linkern.exe')
    postprocess_cyc('extinction_symbol.npy',
                    'extinction_symbol.cyc',
                    'extinction_symbol_processed.npy', (width, height),
                    radius=110 / 128,
                    segment_length=5)
示例#15
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()
示例#16
0
    def make_frame(t):
        speed = t * -20
        surface = gz.Surface(w, h, bg_color=(1, 1, 1))

        x0 = (coords[0] + 1) * scale        # change coords with neat
        x1 = (coords[1] + 1) * scale + speed  # change coords with neat and remove +speed
        height_support = h / 2 + beamheight * 50

        support0 = support.translate(xy=[x0, height_support])
        group = gz.Group((support0,))
        group.draw(surface)

        support1 = support.translate(xy=[x1, height_support])
        group = gz.Group((support1,))
        group.draw(surface)

        group = gz.Group((beam,))
        group.draw(surface)


        # Get the moments
        momentenfunction(beamwidth)
        # Draw text
        text1 = gz.text(str(round(momenten[0])), fontfamily="Impact", fontsize=14, fill=(0, 0, 1), xy=[x0, 30])
        text2 = gz.text(str(round(momenten[1])), fontfamily="Impact", fontsize=14, fill=(0, 0, 1), xy=[(x0 + x1) / 2, 80])
        text3 = gz.text(str(round(momenten[2])), fontfamily="Impact", fontsize=14, fill=(0, 0, 1), xy=[x1, 30])

        group = gz.Group((text1, text2, text3))
        group.draw(surface)

        return surface.get_npimage()
示例#17
0
def make_frame(t):
    surface = gz.Surface(width, height)
    progress = t / duration

    center = width / 2, height / 2 - 18

    circles = [
        geo.Point(center).buffer(r, resolution=32)
        for r in np.arange(5, 0.8 * width, 10)
    ]
    p = [
        interval_progresses(progress + offset, 6, 'hermite')
        for offset in np.linspace(0, 1 / 3, len(circles))[::-1]
    ]
    angles = [
        hermite(hermite(p[i][2] - p[i][5])) * 2 * np.pi for i in range(len(p))
    ]

    arcs = []
    for i, c in enumerate(circles):
        s = xr.intersection(c.exterior)
        if isinstance(s, geo.LineString):
            arcs.append((s, angles[i]))
        elif isinstance(s, geo.MultiLineString):
            arcs.extend([(arc, angles[i]) for arc in s])

    for arc, angle in arcs:
        coords = np.array(arc.coords)
        rotate_around(coords, angle, center)
        gz.polyline(points=coords,
                    stroke=(1, 1, 1),
                    stroke_width=5,
                    line_cap='round').draw(surface)

    return surface.get_npimage()
示例#18
0
def piano_surface(midi, size, offset, time):
    surface = gizeh.Surface(*size)
    current = midi.second2tick(time)
    hit_note_colors = {
        midi.notes[interval[2]]['note']: track_colors[midi.notes[interval[2]]['track'] % 4]
        for interval in midi.timeline[current]
    }

    ivory_params = lambda note: {
        'lx'    : size[0]/52,
        'ly'    : size[1],
        'xy'    : (size[0] * position[note], size[1] / 2),
        'fill'  : hit_note_colors[note][1] if note in hit_note_colors.keys() else RGB('#CBCFCC'),
        'stroke': RGB('#3A3E42'),
        'stroke_width': 1
    }
    ebony_params = lambda note: {
        'lx'  : size[0]/52 * 0.7,
        'ly'  : size[1] * 2/3,
        'xy'  : (size[0] * position[note], size[1] / 3),
        'fill': hit_note_colors[note][0] if note in hit_note_colors.keys() else RGB('#3A3E42')
    }

    for note in filter(is_ivory, range(21, 109)):
        gizeh.rectangle(**ivory_params(note)).draw(surface)
    for note in filter(is_ebony, range(21, 109)):
        gizeh.rectangle(**ebony_params(note)).draw(surface)
    return surface
示例#19
0
    def make_frame_mask(self, t):
        """
		Creates pointer mask.
		"""
        surface = gz.Surface(self.width, self.height, bg_color=(0, 0, 0))
        # rect = gz.rectangle(lx=150, ly=5, xy=(250,250), fill=(1,1,1), angle=3.1415926/(2*t+1))
        rect = gz.rectangle(
            lx=self.p_length + 2 * self.p_glow_margin,
            ly=self.p_width + 2 * self.p_glow_margin,
            xy=(self.p_rot_center_x + self.p_length * self.p_shift,
                self.p_rot_center_y),
            fill=(1, 1, 1))
        rect = rect.rotate(self.speed2angle(t),
                           center=[self.p_rot_center_x, self.p_rot_center_y])
        rect.draw(surface)
        if self.g_text_visible:
            txt = gz.text('{0}'.format(
                int(self.gps_speed[int(t)] * self.unit_conversion_factor)),
                          fontfamily=self.g_text_fontFamily,
                          fontsize=self.g_text_size,
                          xy=(self.g_text_x, self.g_text_y),
                          fill=(1, 1, 1))
            txt.draw(surface)
        arr = surface.get_npimage()
        if self.parent is not None and self.parent.cancelExport is True:
            raise TypeError('Canceling...')
        return arr
    def draw(self):
        surface = gizeh.Surface(width=self.width,
                                height=self.height,
                                bg_color=(1, 1, 1))

        if self.bg:
            fill = gizeh.ImagePattern(self.bg.data, self.bg.pos, filter='best')
            bg_circle = gizeh.circle(r=self.width * 5, fill=fill)
            bg_circle.draw(surface)

        if self.dragon:
            xy_pos = self.dragon.pos
            dragon_circle = gizeh.circle(r=10, xy=xy_pos, fill=(1, 0, 0))
            dragon_circle.draw(surface)

        for target in self.target_list:
            circle = gizeh.circle(r=target.size,
                                  xy=target.pos,
                                  fill=target.color)
            circle.draw(surface)

        surface.get_npimage()

        img_name = "temp/scr" + str(self.time) + ".png"
        surface.write_to_png(img_name)

        self.time += 1
示例#21
0
def make_frame(t):
    progress = t / duration
    p = interval_progresses(progress, 2, 'hermite')
    p = interval_progresses(p[0], 2, 'none') + interval_progresses(
        p[1], 2, 'none')

    # circle
    surface = gz.Surface(2 * width, 2 * height)
    gz.circle(xy=(width, height),
              r=40 + 3 * (p[0] - p[1] - p[2] + p[3]),
              stroke_width=8 + 4 * (p[0] + p[1] - p[2] - p[3]),
              stroke=(1, 1, 1)).draw(surface)

    # FFT
    I = np.fft.fft2(surface.get_npimage()[:, :, 0] / 255)
    I = np.log(np.abs(I) + 0.00001).astype(np.float32)
    I = 1 - np.minimum(1, np.maximum(0, I))
    I = resize(I, (width, height))

    # border
    radius = (300 + 15 * (p[0] + p[1] - p[2] - p[3]))
    I *= get_circle_mask(width, height, radius)
    I = np.tile(I[:, :, np.newaxis], (1, 1, 4)) * 255
    surface = gz.Surface.from_image(I.astype(np.uint8))
    gz.circle(xy=(width / 2, height / 2),
              r=radius,
              stroke=(1, 1, 1),
              stroke_width=2).draw(surface)

    return surface.get_npimage()
示例#22
0
    def render(self, volume, as_html=False):
        self._calc_M()
        surf = gizeh.Surface(width=self.width,
                             height=self.height,
                             bg_color=self.bg_color)
        ijks = np.asarray(np.nonzero(volume), dtype=np.float)
        cube = make_prism((0., 0., 0.), (1., 1., 1.))
        faces, normals = [], []
        for ijk in ijks.T:
            faces.extend([(face.T + ijk).T for face in cube])
        faces = sorted(faces, key=iso_face_depth, reverse=True)
        normals = map(face_normal, faces)
        faces_flat = np.concatenate(faces, 1)

        faces_flat_h = np.vstack((faces_flat, np.ones(faces_flat.shape[1])))
        uvs_flat = np.dot(self.M, faces_flat_h).T
        colors = np.outer(np.dot(normals, self.light_angle), self.base_color)

        for face_ix in range(0, faces_flat.shape[1], 4):
            uvs = uvs_flat[face_ix:face_ix + 4]
            color = colors[face_ix // 4]
            gizeh.polyline(uvs,
                           stroke=self.stroke_color,
                           stroke_width=self.stroke_width,
                           close_path=True,
                           fill=color).draw(surf)
        if as_html:
            return surf.get_html_embed_code()
        return surf.get_npimage()
示例#23
0
 def __init__(self, width = 720, height = 480):
     self.surface = gizeh.Surface(width=width, height=height)
     bg = gizeh.rectangle(lx = width,
                          ly = height,
                          xy=(width//2,height//2),
                          fill=(1,1,1))
     bg.draw(self.surface)
示例#24
0
 def make_frame(t):
     # See example: https://zulko.github.io/moviepy/getting_started/videoclips.html#videoclip
     surface = gizeh.Surface(128, 128)
     radius = 100 * (1 + (t * (2 - t))**2) / 6
     circle = gizeh.circle(radius, xy=(64, 64), fill=(1, 0, 0))
     circle.draw(surface)
     return surface.get_npimage()
示例#25
0
def make_frame(t):
    progress = t / duration
    p = interval_progresses(progress, 2, 'hermite')
    center = (width / 2, height / 2)

    # star
    surface = gz.Surface(2 * width, 2 * height)
    n_lines = 24

    length = 30 + 5 * (p[0] - p[1])
    C = get_circle_coordinates(n_lines, length, center)
    rotate_around(C, -2 * np.pi * progress / n_lines, center)

    for i in range(n_lines):
        gz.polyline(points=[center, C[i, :]], stroke=(1, 1, 1),
                    stroke_width=2).draw(surface)

    # FFT
    I = np.fft.fft2(surface.get_npimage()[:, :, 0] / 255)
    I = np.abs(I).astype(np.float32)
    I -= 1
    I = 1 - np.minimum(1, np.maximum(0, I))
    I = resize(I, (width, height))

    # border
    radius = 300
    I *= get_circle_mask(width, height, radius)
    I = np.tile(I[:, :, np.newaxis], (1, 1, 4)) * 255
    surface = gz.Surface.from_image(I.astype(np.uint8))
    gz.circle(xy=(width / 2, height / 2),
              r=radius,
              stroke=(1, 1, 1),
              stroke_width=3).draw(surface)

    return surface.get_npimage()
示例#26
0
def draw_wavy_lines(size: int,
                    palette: 'models.Palette',
                    count: int = 7,
                    frequency: int = 6) -> gizeh.Surface:
    """ Draws series of wavy vertical lines.

        :param size: Width and height of resulting surface.
        :param palette: The color palette to source colors from.
        :param count: Number of lines.
        :param frequency: Frequency of waves per line.
        :returns: Resulting surface.
    """
    colors = palette.monochromatic(2)
    surface = gizeh.Surface(width=size, height=size)

    for idx in range(count + 1):
        color = colors[idx % len(colors)]
        points = [
            (
                # Px
                ((
                    ((p + p // (frequency + 2)) % 2) / 2 \
                    + idx + (p // (frequency + 2))
                ) - 1) * (size / (count - 1)) \
                + (-1 + (p // (frequency + 2)) * 2),
                # Py
                (jsin(p, frequency + 2) - 1) * (size / (frequency - 1))
            )
            for p in range((frequency + 2) * 2)
        ]
        line = gizeh.polyline(points=points, fill=color)
        line.draw(surface)
    return surface
示例#27
0
def make_frame(t):

    dt = 1.0 * DURATION / 2 / NDISKS_PER_CYCLE  # delay between disks
    N = int(NDISKS_PER_CYCLE / SPEED)  # total number of disks
    t0 = 1.0 / SPEED  # indicates at which avancement to start

    surface = gz.Surface(W, H)
    for i in range(1, N):
        a = (np.pi / NDISKS_PER_CYCLE) * (N - i - 1)
        r = np.maximum(0, .05 * (t + t0 - dt * (N - i - 1)))
        center = W * (0.5 + gz.polar2cart(r, a))
        color = 3 * ((1.0 * i / NDISKS_PER_CYCLE) % 1.0, )
        circle = gz.circle(r=0.3 * W,
                           xy=center,
                           fill=color,
                           stroke_width=0.01 * W)
        circle.draw(surface)
    contour1 = gz.circle(r=.65 * W, xy=[W / 2, W / 2], stroke_width=.5 * W)
    contour2 = gz.circle(r=.42 * W,
                         xy=[W / 2, W / 2],
                         stroke_width=.02 * W,
                         stroke=(1, 1, 1))
    contour1.draw(surface)
    contour2.draw(surface)
    return surface.get_npimage()
def create_frame(t):
    img = gizeh.Surface(videobreite,videohoehe,bg_color=(hgfarbe_r,hgfarbe_g,hgfarbe_b))
    text_img = gizeh.text(text, fontfamily=schrift, fontsize=textgroesse,
               fill=(textfarbe_r,textfarbe_g,textfarbe_b),
               xy=(t*(videobreite/2)/videolaenge,videohoehe/2), angle=winkel)
    text_img.draw(img)
    return img.get_npimage()
 def make_frame(t):
     surface = gz.Surface(width=1920, height=1080)
     line = gz.polyline(points=[(200, max(180, 180 + 100 * t)),
                                (100, max(180, 180 + 100 * t))],
                        stroke_width=25,
                        stroke=(1, 0, 0))
     line.draw(surface)
     return surface.get_npimage(transparent=True)
示例#30
0
def create_frame(t):
    img = gizeh.Surface(videobreite,videohoehe,bg_color=(hgfarbe_r,hgfarbe_g,hgfarbe_b))
    text_img = gizeh.text(text, fontfamily=schrift, fontsize=textgroesse,
               fill=(textfarbe_r,textfarbe_g,textfarbe_b),
               xy=(videobreite/2,videohoehe-t*(videohoehe/2)/videolaenge))
    text_rotation = text_img.rotate(t*(2*3.1415/videolaenge), center=[videobreite/2,videohoehe-t*(videohoehe/2)/videolaenge])
    text_rotation.draw(img)
    return img.get_npimage()