Exemplo n.º 1
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()
Exemplo n.º 2
0
    def draw(self, surface: gizeh.Surface) -> None:
        """Draw the pitch's label on the tone clock."""
        scale = self._style.marking_scale
        rotation = self.get_mark_rotation() % TAU

        # TODO: Rotation of labels appears to be broken. Revisit this and add a style flag to turn rotation on/off,
        #       with off being the default.
        # label_rotation = rotation % pi

        if abs(rotation -
               (pi +
                RIGHT_ANGLE)) < FLOAT_TOLERANCE:  # Top center (12 o'clock)
            v_align = "top"
            h_align = "center"
        elif abs(rotation -
                 RIGHT_ANGLE) < FLOAT_TOLERANCE:  # Bottom center (6 o'clock)
            v_align = "bottom"
            h_align = "center"
        elif rotation < FLOAT_TOLERANCE or TAU - rotation < FLOAT_TOLERANCE:  # Center right (3 o'clock)
            v_align = "center"
            h_align = "left"
        elif abs(rotation -
                 (TAU -
                  RIGHT_ANGLE)) < FLOAT_TOLERANCE:  # Center left (9 o'clock)
            v_align = "center"
            h_align = "right"
        elif rotation < RIGHT_ANGLE:  # Bottom right quadrant (3 to 6)
            v_align = "bottom"
            h_align = "left"
        elif rotation < pi:  # Bottom left quadrant (6 to 9)
            v_align = "bottom"
            h_align = "right"
        elif rotation < pi + RIGHT_ANGLE:  # Top left quadrant (9 to 12)
            v_align = "top"
            h_align = "right"
        else:  # Top right quadrant (12 to 3)
            v_align = "top"
            h_align = "left"

        xy = self.get_mark_point(elevation=20 * scale)
        gizeh.text(
            self._label,
            self._style.font_family,
            self._style.font_size,
            # angle=label_rotation,
            xy=xy,
            fill=BLACK,
            stroke=BLACK,
            stroke_width=1,
            v_align=v_align,
            h_align=h_align).draw(surface)
Exemplo n.º 3
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()
Exemplo n.º 4
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')
Exemplo n.º 5
0
def make_frame(t):
    """Draw text elements in each frame"""
    surface = gz.Surface(W, H, bg_color=(0,0,0))
    for i, line in enumerate(text):
        job, name = line
        ypos = LINE_HEIGHT * i - int(t * SCROLLSPEED) + BOTTOM_START
        
        txt = gz.text(job, "Amiri", TEXTSIZE, fontweight='bold', \
                      h_align='right', fill=(1,1,1))
        left = gz.Group([txt]).translate((LEFTCOL, ypos))
        left.draw(surface)
        txt = gz.text(name, "Amiri", TEXTSIZE, \
                      fontweight='normal',h_align='left', fill=(1,1,1))
        right = gz.Group([txt]).translate((RIGHTCOL, ypos))
        right.draw(surface)
    return surface.get_npimage()
Exemplo n.º 6
0
def test_pdfsurface(tmpdir):
    """Test PDFSurface class."""
    # 800x800 point image
    im_size = 800

    # Create a simple star shape with a fill
    shape = gz.star(stroke_width=0.01, fill=(0, 0, 0.3, 0.7))
    shape = shape.rotate(-3.14159265358979 / 2.0)
    shape = shape.scale((im_size - 100) // 2)
    shape = shape.translate([im_size // 2, im_size // 2])

    # Some text to throw on the shape...
    txt = gz.text("Gizeh on pdf",
                  fontfamily="Arial",
                  fontsize=50,
                  fill=(0, 0, 0),
                  xy=(im_size // 2, im_size // 2))

    # Create pdf surface
    filepath = os.path.join(str(tmpdir), "pdfsurface_test.pdf")
    s = gz.PDFSurface(filepath, im_size, im_size)
    # Draw shape on the PDF surface
    shape.draw(s)
    txt.draw(s)

    # Write file and close surface
    s.flush()
    s.finish()
Exemplo n.º 7
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
Exemplo n.º 8
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 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,t*(videohoehe/2)/videolaenge), angle=winkel)
    text_img.draw(img)
    return img.get_npimage()
Exemplo n.º 10
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
Exemplo n.º 11
0
 def make_frame(t):
     s = math.floor(t)
     surface = gz.Surface(1280, 720)
     xy = [158, 54]
     for c in reversed(list(str(df.iloc[s]['power']))):
         power = gz.text(c, "Helvetica Neue", 83, fontweight="bold",
                         xy=xy, fill=(1, 1, 1), v_align="center", h_align="center")
         power.draw(surface)
         xy[0] -= 45
     xy = [170, 115]
     for c in reversed(list(str(df.iloc[s]['heart_rate']))):
         hr = gz.text(c, "Helvetica Neue", 38, fontweight="bold",
                      xy=xy, fill=(0, 0, 0), v_align="center", h_align="center")
         hr.draw(surface)
         xy[0] -= 22
     return surface.get_npimage(transparent=True)
Exemplo n.º 12
0
def make_movie(duration_seconds, output_filename):

    w, h = 500, 100
    scale = 50
    beamwidth = 8  # beam width in m
    beamheight = 0.2
    coords[0] = 0  # Start position of first pole relative to start of beam
    coords[1] = 8  # random position of 2nd pole relative to start of beam

    # TODO: Change like in testfile, start at 0,0, change coords in make_frame file. Also add 1 general textfile that you change
    # Standard support
    # To use, translate support in make_frame, it will create a copy
    support = gz.rectangle(scale * .2, scale * 0.25, xy=[0, 0], stroke_width=1, fill=(0, 1, 0))

    # Beam at center of screen
    beam = gz.rectangle(scale * beamwidth, scale * beamheight, xy=[w / 2, h / 2], stroke_width=1, fill=(1, 1, 0))

    # Standard text at 0, 0
    text = gz.text(str('placeholder'), fontfamily="Impact", fontsize=14, fill=(0, 0, 1),
                    xy=[0, 0])
    '''
    paal1 = gz.rectangle(scale * .2, scale * 0.25, xy=((coords[0] + 1) * scale, h / 2 + 10), stroke_width=1, fill=(0, 1, 0))
    paal2 = gz.rectangle(scale * .2, scale * 0.25, xy=((coords[1] + 1) * scale, h / 2 + 10), stroke_width=1, fill=(0, 1, 0))
    pole = gz.rectangle(scale * beamwidth, scale * beamheight, xy=(w / 2, h / 2), stroke_width=1, fill=(1, 1, 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()

    clip = mpy.VideoClip(make_frame, duration=duration_seconds)
    clip.write_videofile(output_filename, codec="mpeg4", fps=50)
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()
Exemplo n.º 14
0
def test_pdfsurface():
    """Test PDFSurface class."""
    # 800x800 point image
    im_size = 800

    # Create a simple star shape with a fill
    shape = gz.star(stroke_width=0.01, fill=(0, 0, 0.3, 0.7))
    shape = shape.rotate(-3.14159265358979 / 2.0)
    shape = shape.scale((im_size - 100) // 2)
    shape = shape.translate([im_size // 2, im_size // 2])

    # Some text to throw on the shape...
    txt = gz.text("Gizeh on pdf",
                  fontfamily="Arial",
                  fontsize=50,
                  fill=(0, 0, 0),
                  xy=(im_size // 2, im_size // 2))

    # Create pdf surface
    s = gz.PDFSurface("pdfsurface_test.pdf", im_size, im_size)
    # Draw shape on the PDF surface
    shape.draw(s)
    txt.draw(s)

    # Write file and close surface
    s.flush()
    s.finish()

    # Delete test PDF
    os.remove("pdfsurface_test.pdf")
Exemplo n.º 15
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()
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=t*(textgroesse/videolaenge),
               fill=(textfarbe_r,textfarbe_g,textfarbe_b),
               xy=(videobreite/2,videohoehe/2))
    text_rotation = text_img.rotate(t*(2*3.14/videolaenge), center=[videobreite/2,videohoehe/2])
    text_rotation.draw(img)
    return img.get_npimage()
Exemplo n.º 17
0
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()
Exemplo n.º 18
0
def make_station_icon(surface, settings, n, constants, text=None):
    x_pos, y_pos = constants.icon_xy
    if constants.theme.lower() == 'tokyu':
        fill = constants.line_color
        stroke = [1, 1, 1]
        stroke_width = 5
        text_fill = [1, 1, 1]
        letter_mod = -10
    else:
        fill = [1, 1, 1]
        stroke = constants.line_color
        stroke_width = 15
        text_fill = [0, 0, 0]
        letter_mod = 0

    if constants.icon_shape.lower() == 'square':
        mod = 40
        gz.square(constants.icon_size,
                  xy=[x_pos, y_pos],
                  stroke=stroke,
                  stroke_width=stroke_width,
                  fill=fill).draw(surface)
    else:
        mod = 45
        gz.circle(constants.icon_size,
                  xy=[x_pos, y_pos],
                  stroke=constants.line_color,
                  stroke_width=30,
                  fill=[1, 1, 1]).draw(surface)

    if text:
        line, num = text.split('-')
    else:
        line, num = settings[n].station_number.split('-')
    gz.text(line,
            constants.icon_text_font,
            constants.icon_line_fontsize + letter_mod,
            xy=[x_pos, y_pos - mod],
            fill=text_fill).draw(surface)
    gz.text(num,
            constants.icon_text_font,
            constants.icon_station_fontsize - letter_mod,
            xy=[x_pos, y_pos + 30],
            fill=text_fill).draw(surface)
Exemplo n.º 19
0
def draw_sqr(color, x, y):
    sqr = gz.square(l=500, fill=color, xy=(x, y))

    r = int(color[0] * 255)
    g = int(color[1] * 255)
    b = int(color[2] * 255)
    string = "(" + str(r) + ", " + str(g) + ", " + str(b) + ")"
    text2 = gz.text(string,
                    fontfamily="Tahoma",
                    fontsize=24,
                    fill=(0, 0, 0),
                    xy=(x + 20, y + 20))
    text3 = gz.text(string,
                    fontfamily="Tahoma",
                    fontsize=23,
                    fill=(1, 1, 1),
                    xy=(x + 20, y + 20))

    return gz.Group([sqr, text2, text3])
Exemplo n.º 20
0
 def text(self, string, position, style = monospace30):
     string = str(string)
     for s in style:
         text = gizeh.text(string,
                           s.fontfamily,
                           s.fontsize,
                           fill = s.fill,
                           xy = position,
                           )
         text.draw(self.surface)
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()
Exemplo n.º 22
0
 def render_text(t):
     surface = gz.Surface(1280, 300, bg_color=WHITE_GIZEH)
     # add original text to screen
     text1 = gz.text(untranslated_text,
                     fontfamily="Charter",
                     fontsize=40,
                     fontweight='bold',
                     fill=BLUE,
                     xy=(640, 40))
     text1.draw(surface)
     # add translated text to screen
     text2 = gz.text(translated_text,
                     fontfamily="Charter",
                     fontsize=40,
                     fontweight='bold',
                     fill=BLUE,
                     xy=(640, 200))
     text2.draw(surface)
     return surface.get_npimage()
Exemplo n.º 23
0
def make_frame(t):

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

    rect = gz.rectangle(lx = 10, ly = 10, xy=(W/(t+1),H/2), fill =(0,1,0.7))
    rect.draw(surface)
    txt = gz.text(str(t+1), fontfamily="Impact", fontsize=15, fill=(0,0,0),xy=(W/(t+1),H/2))
    txt.draw(surface)

    return surface.get_npimage()
Exemplo n.º 24
0
def makeText(t):
    img = imageio.imread(args.background)
    W = img.shape[1]
    H = img.shape[0]
    surface = gizeh.Surface.from_image(img)
    x = W * t / DURATION
    y = H * t / DURATION
    text = gizeh.text(args.text, fontfamily="Helvetica",  fontsize=5, fill=(255,255,255), xy=(x,y))
    text.draw(surface)
    return surface.get_npimage()
Exemplo n.º 25
0
def make_scale_text_frames(t, duration, surface, skip_if_t, scaler_func, text,
                           xy, font, fontsize, fontcolor, x_scale, center_xy,
                           alpha_func):
    '''Draws either a text showing or hiding animation'''
    if t != skip_if_t:
        color = list(fontcolor) + [alpha_func(t, duration)]
        scaler = scaler_func(t, duration)
        new = gz.text(text, font, fontsize, xy=xy, fill=color)
        new.scale(rx=x_scale, ry=scaler, center=center_xy).draw(surface)
    return surface
Exemplo n.º 26
0
def render_info(info_value, shape):
    vertical_spacing = 22
    surface = gizeh.Surface(width=shape[1], height=shape[0])
    for i, (key, value) in enumerate(info_value.items()):
        text = gizeh.text('{0}: {1:.4}'.format(key, value),
                          fontfamily="Helvetica",
                          fontsize=18,
                          fill=(1, 1, 1),
                          xy=(10, (i + 0.5) * vertical_spacing),
                          angle=0,
                          h_align='left')
        text.draw(surface)
    return surface.get_npimage()
Exemplo n.º 27
0
def render_keys(keys_down):
    isdown_layout = set2layout(keys_down)

    s = gz.Surface(RES[0] + 2 * BORDER, RES[1] + 2 * BORDER)
    #gz.rectangle(xy=(RES[0]/2, RES[1]/2), lx=RES[0], ly=RES[1], fill=(0,1,0)).draw(s) # greenscreen?
    gz.rectangle(xy=(RES[0] / 2 + BORDER, RES[1] / 2 + BORDER),
                 lx=RES[0],
                 ly=RES[1],
                 fill=BORDER_RGBA).draw(s)

    row_height = RES[1] / len(chars_layout)

    xy = v([BORDER, -row_height / 2 + BORDER])

    for row, downs in zip(chars_layout, isdown_layout):
        xy += v([0, row_height])  # place pen at start pos for row

        tot_chars = sum([len(col) for col in row])

        for col, is_down in zip(row, downs):
            col_width = RES[0] * len(col) / tot_chars
            xy += v([col_width / 2, 0])  # advance pen

            if col != ' ':
                fill = (0.5, 0.5, 1,
                        ALPHA_PRESSED) if is_down else (0.2, 0.2, 0.4, ALPHA)
                gz.rectangle(xy=xy,
                             lx=col_width,
                             ly=row_height,
                             fill=fill,
                             stroke=BORDER_RGBA,
                             stroke_width=BORDER).draw(s)
                gz.text(col, 'Arial', 60, fill=(1, 1, 1, ALPHA), xy=xy).draw(s)

            xy += v([col_width / 2, 0])  # advance pen

        xy[0] = BORDER

    return s
Exemplo n.º 28
0
 def render(self, time):
     """
     create gizeh object
     :param time: current time
     :return: gizeh object
     """
     alph = get_alpha(self, time)
     circle = gizeh.circle(self.radius - 5, xy=self.position,
                           stroke=(*self.border, alph), stroke_width=5, fill=(*self.color, alph))
     num = gizeh.text(str(self.num), fontfamily="Impact", fontsize=self.radius,
                      fill=(0, 0, 0, alph), xy=self.position)
     appr_circle = approach_circle(self, time)
     return [circle, num, appr_circle]
def make_frame(t):
    
    frame = int(math.floor(t*60))
    print(frame)

    #Essentially pauses the action if there are no more frames and but more clip duration
    if frame >= len(events["A"]):
        frame = len(events["A"])-1

    #White background
    surface = gz.Surface(W,H, bg_color=(1,1,1))            

    #Pucks
    for label, center in zip(labels, centers):

        xy = [center[0], center[1]]

        if events[label][frame]==1:
            #Event
            ball = gz.circle(r=RAD, fill=(1,1,0), stroke=(0,0,0), stroke_width=1).translate(xy)
            ball.draw(surface)

            # text = gz.text(label, fontfamily="Helvetica", 
            # fontsize=25, fontweight='bold', fill=(0.2,0.2,0.2), xy=xy) #, angle=Pi/12
            # text.draw(surface)
        elif events[label][frame]==2:
            #Action/intervention
            ball = gz.circle(r=RAD, fill=(1,1,0), stroke=(0,0,0), stroke_width=6).translate(xy)
            ball.draw(surface)

            text = gz.text('+', fontfamily="Helvetica",  fontsize=35, fontweight='bold', fill=(0,0,0), xy=xy) #, angle=Pi/12
            text.draw(surface)

            # timeline = gz.rectangle(251,201, fill=gz.ImagePattern(image), xy=xy)
            # timeline.draw(surface)
        elif events[label][frame]==0:
            #Inactive
            ball = gz.circle(r=RAD, fill=(.7,.7,.7), stroke=(0,0,0), stroke_width=1).translate(xy)
            ball.draw(surface)
                    #Letters
            # text = gz.text(label, fontfamily="Helvetica", 
            # fontsize=25, fontweight='bold', fill=(0.2,0.2,0.2), xy=xy) #, angle=Pi/12
            # text.draw(surface)


    #Mouse cursor
    # cursor_xy = np.array([this_events['mouse']['x'][frame]*RATIO, this_events['mouse']['y'][frame]*RATIO])
    # cursor = gz.text('+', fontfamily="Helvetica",  fontsize=25, fill=(0,0,0), xy=cursor_xy) #, angle=Pi/12
    # cursor.draw(surface)
    
    return surface.get_npimage()  
    def epoch_finished(self, epoch):
        num_words = len(self.words)
        surface = gizeh.Surface(width=1200, height=self.height)
        background = gizeh.rectangle(lx=1200, ly=self.height, xy=[600,750], fill=(0,0,0))
        background.draw(surface)

        gizeh.text('%s   epoch %s' % (self.title, epoch),
                   fontfamily='Arial',
                   fontsize=20,
                   fill=(.6,.6,.6),
                   xy=(70,40),
                   h_align='left').draw(surface)
        
        weights = self.rbm.weights.get_value()
        for block in range(self.tuplesize):
            for word in range(num_words):
                x = 40
                y = 70+22*(block*(num_words+2)+word)
                gizeh.text('%s %s' % (block, self.words[word]),
                           fontfamily='Arial',
                           fontsize=12,
                           fill=(.7,.7,.7),
                           xy=(x,y),
                           h_align='left').draw(surface)
        for block in range(self.tuplesize):
            for word in range(num_words):
                for h in range(self.num_hidden):
                    vis = block*num_words+word
                    w = weights[vis, h]
                    r = math.log(1+abs(w))*4
                    x = 100+22*h
                    y = 70+22*(block*(num_words+2)+word)
                    col = (1,1,0)
                    if w < 0:
                        col = (.4,.4,.4)
                    circle = gizeh.circle(r=r, xy=[x,y], fill=col)
                    circle.draw(surface)
        surface.write_to_png("epoch-%03d.png" % epoch)
Exemplo n.º 31
0
 def render(self, time):
     """
     create gizeh object
     :param time: current time
     :return: gizeh object
     """
     alph = get_alpha(self, time)
     slide = self.slide(alph)
     ball = self.ball(time, alph)
     appr_circle = approach_circle(self, time)
     numb = alph if time <= self.action else 0
     num = gizeh.text(str(self.num), fontfamily="Impact", fontsize=self.radius,
                      fill=(0, 0, 0, numb), xy=self.position)
     return [slide, appr_circle, ball, num]
Exemplo n.º 32
0
 def draw_text(self, text):
     props = self.props(
         text.props,
         'stroke',
         'fill',
         'font_size',
         'font_family',
         'font_weight',
         # 'dominant_baseline',
         # 'text_anchor',
     )
     string = text.text
     gtext = gizeh.text(text.text, xy=text.position, **props)
     gtext.draw(self.surface)
Exemplo n.º 33
0
def draw_list(list, count):
    length = len(list)
    for index in range(length):
        color = (random_color_r + list[index] * 0.2625,
                 random_color_g + list[index] * 0.123625, 0)
        circle = gizeh.circle(r=30,
                              xy=[80 * (index + 1), 100 * (count + 1)],
                              fill=color)
        text = gizeh.text(str(list[index]),
                          fontfamily="Impact",
                          fontsize=40,
                          fill=(0, 0, 0),
                          xy=(80 * (index + 1), 100 * (count + 1)))
        group = gizeh.Group([circle, text])
        group.draw(surface)
Exemplo n.º 34
0
 def make_text(self, text, where='bottom'):
     if text is None:
         return None
     if where == 'top':
         xy = (self.bgr.size[0] // 2, int(self.bgr.size[1] * 0.1))
     else:
         xy = (self.bgr.size[0] // 2, int(self.bgr.size[1] * 0.9))
     return gz.text(text,
                    xy=xy,
                    fontfamily='Impact',
                    fontsize=self.font_size,
                    fontweight='bold',
                    fill=(1, 1, 1),
                    stroke=(0, 0, 0),
                    stroke_width=2)
Exemplo n.º 35
0
def make_frame_1_r(t):
    sentence = sentence1
    surface = gizeh.Surface(width=w, height=h,
                            bg_color=(1, 1, 1))  # dimensions in pixel

    try:
        word = str(sentence[sentence.label_cumsum > t].word.iloc[0])
    except:
        word = ''

    text = gizeh.text(word,
                      fontfamily="Helvetica",
                      fontsize=140,
                      fill=(0, 0, 0),
                      xy=(w / 2, h / 2))
    text.draw(surface)
    return surface.get_npimage()
Exemplo n.º 36
0
def make_frame(t):
	global fsize
	#create image on the surface
	im = imageio.imread("Liger.png")
	surface = gizeh.Surface.from_image(im)
	#grab width and height
	x = im.shape[1]
	y = im.shape[0]
	#start in the middle
	xmid = x/2
	#have the text move up
	y = y - t*130
	#increase font size by 1
	fsize = fsize + 1
	#set the text font, font size, font weight, color, and starting x and y position
	txt = gizeh.text(letter, fontfamily="Impact", fontsize=fsize, fontweight='bold', fill=(0,0,1), xy=(xmid, y))
	#draw the text on the surface
	txt.draw(surface)
	return surface.get_npimage()
Exemplo n.º 37
0
def make_frame_u(t):
    sentence = sentence_u
    surface = gizeh.Surface(width=w, height=h,
                            bg_color=(1, 1, 1))  # dimensions in pixel

    avg_wps = (sentence.index.max() + 1) / su_pred_time

    i = floor(t * avg_wps)

    try:
        word = str(sentence.word.iloc[i])
    except:
        word = ''

    text = gizeh.text(word,
                      fontfamily="Helvetica",
                      fontsize=140,
                      fill=(0, 0, 0),
                      xy=(w / 2, h / 2))
    text.draw(surface)
    return surface.get_npimage()
Exemplo n.º 38
0
def text_curve(server_no, message, angle, spacing, ts):
    cr = server_no * ring_rad + (ring_rad / 5) + (ring_rad * start_ring)
    # Start in the center and draw the circle
    # circle = g.circle(r=cr-(ring_rad/2), xy = [w/2, h/2], stroke=(1,0,0), stroke_width= 1.5)
    # circle.draw(surface)
    # We must keep track of our position along the curve
    arclength = -10
    # For every letter
    for i in reversed(range(len(message))):
        currentChar = message[i]

        # print(message[i])
        # guessing the width of each char

        # Each box is centered so we move half the width
        arclength = arclength - spacing / 2
        # print("arclength")
        # print(arclength)
        # Angle in radians is the arclength divided by the radius
        # Starting on the left side of the circle by adding PI
        theta = (-1 / 2 * Pi) + arclength / cr + angle
        # print("theta")
        # print(theta)
        # Polar to cartesian coordinate conversion
        # add 250 so that the origin translates to center of screen, then add coords
        x = w / 2 + cr * math.cos(theta)
        y = h / 2 + cr * math.sin(theta)
        # Display the character

        text = g.text(message[i].capitalize(),
                      fontfamily="Georgia",
                      fontsize=ts,
                      fill=(1, 1, 1),
                      xy=[x, y])
        text = text.rotate(theta + (Pi / 2),
                           center=[x, y])  # rotation around a center
        text.draw(surface)
        # popMatrix()
        # Move halfway again
        arclength -= spacing / 2
Exemplo n.º 39
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
Exemplo n.º 40
0
# white keys
white_count = 7
white_size = (width / white_count, height)
for i in range(white_count):
    w, h = white_size
    rect = gz.rectangle(lx=w-5, ly=h-5,
        xy=[(i + 0.5) * w, h / 2],
        stroke=(0.8, 0.8, 0.8), stroke_width=2)
    rect.draw(surface)

# black keys
for i in (0, 1, 3, 4, 5):
    w, h = white_size[0] * 0.85, (white_size[1] * 0.65)
    rect = gz.rectangle(lx=w-5, ly=h-5,
        xy=[(i + 0.5 + 0.5) * white_size[0], h / 2],
        fill=(0.1, 0.1, 0.1))
    rect.draw(surface)

for i, label in enumerate(('C', 'D', 'E', 'F', 'G', 'A', 'B')):
    text = gz.text(label, 'Helvetica', white_size[0]*0.4,
        xy=[(i + 0.5) * white_size[0], height * 0.85])
    text.draw(surface)

for i, label in ((0, 'Db'), (1, 'Eb'), (3, 'Gb'), (4, 'Ab'), (5, 'Bb')):
    text = gz.text(label, 'Helvetica', white_size[0]*0.35,
        xy=[(i + 0.5 + 0.5) * white_size[0], height * 0.55],
        fill=(1,1,1))
    text.draw(surface)

surface.write_to_png('piano-octave.png')
Exemplo n.º 41
0
import gizeh as gz
import numpy as np

# PARAMETERS

L = 600 # Picture dimension
r = 100  # Size of the triangles
angles = np.arange(3)*2*np.pi/3 # directions 3h00, 7h00, 11h00

# INITIALIZE THE SURFACE

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)