def draw_pacman_right(x, y, r, img, ma, color_r, color_g, color_b):
"""Draws a Pacman to img
Args:
x, int, x location in img (center of pacman)
y, int, y location in img (center of pacman)
r, int, radius of pacman
img, np.array, 3D color image matrix
ma, float, angle mouth is open at ("mouth angle")
color_r, float, red channel of color
color_g, float, green channel of color
color_b, float, blue channel of color
"""
y_start = int(max(0, y - r))
y_stop = int(min(y + r, img.shape[0] - 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))
# top half of mouth:
if y_i > y - float(r) * math.sin(ma) and y_i <= y:
r_mouth = float(y - y_i) / math.sin(ma)
x_stop = int(x + r_mouth * math.cos(ma))
# bottom half of mouth:
elif y_i < y + float(r) * math.sin(ma) and y_i > y:
r_mouth = float(y_i - y) / math.sin(ma)
x_stop = int(x + r_mouth * math.cos(ma))
for x_i in range(x_start, x_stop):
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:
draw_circle(x, y - int(r / 2), int(r / 10.), img, 0, 0, 0)
评论列表
文章目录