pygame角が丸い
角が丸い四角形を描写する
def circle(rect, radius ,first_rad , end_rad, color ,screen, points = 30, width = 5):
# 半円を描画
center_x = rect.x
center_y = rect.y
# 半円の点を生成
angle_range = np.linspace(first_rad, end_rad, points)
points = [(int(center_x + radius * np.cos(angle)), int(center_y + radius * np.sin(angle))) for angle in angle_range]
if width == 0:
pg.draw.polygon(screen, color, points)
else :
# 点同士を線でつなぐ
pg.draw.lines(screen, color, False, points, width)
def tetragon(rect, color, width, radius, screen):
if width == 0:
pg.draw.rect(screen, color, pg.Rect(rect.x, rect.y + radius, rect.w, rect.h - radius * 2), width) # 横
pg.draw.rect(screen, color, pg.Rect(rect.x + radius, rect.y, rect.w - radius * 2, rect.h), width) # 横
circle(pg.Rect(rect.x + radius,rect.y + radius,rect.w,rect.h), radius, 0,np.pi * 2,color, screen,100, width)
circle(pg.Rect(rect.x - radius + rect.w + 1,rect.y + radius ,rect.w,rect.h), radius, 0,np.pi * 2,color, screen,100, width)
circle(pg.Rect(rect.x - radius + rect.w + 1,rect.y + rect.h - radius + 1 ,rect.w,rect.h), radius, 0, np.pi * 2,color, screen,100, width)
circle(pg.Rect(rect.x + radius,rect.y + rect.h - radius + 1 ,rect.w,rect.h), radius, 0, np.pi * 2,color, screen,100, width)
else:
pg.draw.line(screen, color, (rect.x + radius, rect.y), (rect.x + rect.w - radius, rect.y), width)
pg.draw.line(screen, color, (rect.x + rect.w, rect.y + radius), (rect.x + rect.w, rect.y + rect.h - radius), width)
pg.draw.line(screen, color, (rect.x + radius, rect.y + rect.h), (rect.x + rect.w - radius, rect.y + rect.h), width)
pg.draw.line(screen, color, (rect.x, rect.y + radius), (rect.x, rect.y + rect.h - radius), width)
circle(pg.Rect(rect.x + radius,rect.y + radius,rect.w,rect.h), radius, np.pi, np.pi + np.pi / 2,color, screen,100, width)
circle(pg.Rect(rect.x - radius + rect.w + 1,rect.y + radius ,rect.w,rect.h), radius, np.pi + np.pi / 2,np.pi * 2,color, screen,100, width)
circle(pg.Rect(rect.x - radius + rect.w + 1,rect.y + rect.h - radius + 1 ,rect.w,rect.h), radius, 0, np.pi / 2,color, screen,100, width)
circle(pg.Rect(rect.x + radius,rect.y + rect.h - radius + 1 ,rect.w,rect.h), radius, np.pi / 2, np.pi,color, screen,100, width)