pacman.py 文件源码

python
阅读 19 收藏 0 点赞 0 评论 0

项目:vizgen 作者: uva-graphics 项目源码 文件源码
def draw_ghost(x, y, r, img, color_r, color_g, color_b, tf, blink):
    """Draws a ghost to img

    Args:
        x, int, x location in img
        y, int, y location in img
        r, int, radius of the ghosts's head
        img, np.array, 3D color image matrix
        color_r, int, red channel of color
        color_g, int, green channel of color
        color_b, int, blue channel of color
        tf, float, how much of ghost is not tentacles
        blink, boolean, whether or not the ghost should be blinking
    """

    y_start = int(max(0, y - r))
    y_stop = int(min(y + r, img.shape[1] - 1))

    for y_i in range(y_start, y_stop):
        x_start = int(x - math.sqrt(r**2 - (y - y_i)**2))
        x_stop = int(x + math.sqrt(r**2 - (y - y_i)**2))

        # bottom half of ghost:
        if y_i > y:
            x_start = int(max(0, x - r))
            x_stop = int(min(x + r, img.shape[0] - 1))

        # print(x_start, x_stop, y_start, y_stop)

        for x_i in range(x_start, x_stop):
            if y_i <= y + tf * r:
                img[x_i, y_i, 0] = color_r
                img[x_i, y_i, 1] = color_g
                img[x_i, y_i, 2] = color_b
            else:
                if x_i < x - r * 5/7. or (x_i > x - r * 3/7. and x_i < x - r * 1/7.) or (x_i > x + r * 1/7. and x_i < x + r * 3/7.) or (x_i > x + r * 5/7.):
                    img[x_i, y_i, 0] = color_r
                    img[x_i, y_i, 1] = color_g
                    img[x_i, y_i, 2] = color_b

    # draw the eye:
    if not blink:
        draw_circle(x - int(r / 4), y - int(r / 2), int(r / 5.), img, 1, 1, 1)
        draw_circle(x + int(r / 4), y - int(r / 2), int(r / 5.), img, 1, 1, 1)
        draw_circle(x - int(r / 8.), y - int(r / 2), int(r / 9.), img, 0, 0, 1)
        draw_circle(x + int(r * 3 / 8.), y - int(r / 2), int(r / 9.), img, 0, 0, 1)
    else:
        draw_rect(y - int(r / 2), x - int(r / 4), r / 8., r / 4., img, 0, 0, 0)
        draw_rect(y - int(r / 2), x + int(r / 4), r / 8., r / 4., img, 0, 0, 0)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号