def draw_arc(screen, field, color, center, radius, start_angle, end_angle, thickness=2): p = field.fit_on_screen(center + Vector(-radius, radius)) x, y = field.fit_on_screen(center) r = pygame.Rect(p.x, p.y, field.scale(2 * radius), field.scale(2 * radius)) #pygame.draw.ellipse(screen, color, r, thickness) #pygame.draw.arc(screen, color, r, start_angle, end_angle, thickness) gfxdraw.arc(screen, x, y, int(field.scale(radius)), int(degrees(-end_angle)), int(degrees(-start_angle)), color)
def blit_borders_on(self, surface): if not self.light: white = make_compatible(constants.WHITE, self.color) self.light = mid_color(self.color, white) if not self.dark: black = make_compatible(constants.BLACK, self.color) self.dark = mid_color(self.color, black) ## rect = Rect((0, 0), self.size) x = y = r = self.size[0] // 2 r -= 2 filled_circle(surface, x, y, r, self.color) ## circle(surface, x, y, r, self.dark) arc(surface, x, y, r, 135, 135 + 180, self.dark) arc(surface, x, y, r, 135 + 180, 135 + 360, self.light)
def drawRoundRect(surface, x, y, width, height, bevelsize, color): gfxdraw.hline(surface, x + bevelsize, (x + width) - bevelsize, y, color) gfxdraw.hline(surface, x + bevelsize, (x + width) - bevelsize, y + height, color) gfxdraw.vline(surface, x, y + bevelsize, (y + height) - bevelsize, color) gfxdraw.vline(surface, x + width, y + bevelsize, (y + height) - bevelsize, color) gfxdraw.arc(surface, x + bevelsize, y + bevelsize, bevelsize, 180, 270, color) gfxdraw.arc(surface, x + width - bevelsize, y + bevelsize, bevelsize, 270, 360, color) gfxdraw.arc(surface, x + bevelsize, y + height - bevelsize, bevelsize, 90, 180, color) gfxdraw.arc(surface, x + width - bevelsize, y + height - bevelsize, bevelsize, 0, 90, color)
def arc(self, x, y, r, start, end, color): """円の弧を描画します. Parameters ---------- x : int 円の中心のx座標. y : int 円の中心のy座標. r : int 円の半径. start : float 弧の始点に対応する角度. 単位はラジアン. end : float 弧の終点に対応する角度. 単位はラジアン. color : tuple of int 描画に使用される色を指定します. """ return gfx.arc(self.pg.screen, x, y, r, start, end, color)
def _draw(self, deco: List[Tuple[int, str, Any]], surface: 'pygame.Surface') -> None: """ Draw. :param deco: Decoration list :param surface: Pygame surface :return: None """ if len(deco) == 0: return rect = self._obj.get_rect() for d in deco: dtype, decoid, data = d if not self._decor_enabled[decoid]: continue if dtype == DECORATION_POLYGON: points, color, filled, width, gfx, kwargs = data points = self._update_pos_list(rect, decoid, points, **kwargs) if gfx: if filled: gfxdraw.filled_polygon(surface, points, color) else: gfxdraw.polygon(surface, points, color) else: pydraw.polygon(surface, color, points, width) elif dtype == DECORATION_CIRCLE: points, r, color, filled, width, gfx, kwargs = data points = self._update_pos_list(rect, decoid, points, **kwargs) x, y = points[0] if filled: if gfx: gfxdraw.filled_circle(surface, x, y, r, color) else: pydraw.circle(surface, color, (x, y), r) else: pydraw.circle(surface, color, (x, y), r, width) elif dtype == DECORATION_SURFACE or dtype == DECORATION_BASEIMAGE or dtype == DECORATION_TEXT: pos, surf, centered, kwargs = data if isinstance(surf, pygame_menu.BaseImage): surf = surf.get_surface(new=False) pos = self._update_pos_list(rect, decoid, pos, **kwargs)[0] surfrect = surf.get_rect() surfrect.x += pos[0] surfrect.y += pos[1] if centered: surfrect.x -= surfrect.width / 2 surfrect.y -= surfrect.height / 2 surface.blit(surf, surfrect) elif dtype == DECORATION_ELLIPSE: pos, rx, ry, color, filled, kwargs = data pos = self._update_pos_list(rect, decoid, pos, **kwargs)[0] if filled: gfxdraw.filled_ellipse(surface, pos[0], pos[1], rx, ry, color) else: gfxdraw.ellipse(surface, pos[0], pos[1], rx, ry, color) elif dtype == DECORATION_CALLABLE: data(surface, self._obj) elif dtype == DECORATION_CALLABLE_NO_ARGS: data() elif dtype == DECORATION_TEXTURE_POLYGON: pos, texture, tx, ty, kwargs = data pos = self._update_pos_list(rect, decoid, pos, **kwargs) if isinstance(texture, pygame_menu.BaseImage): texture = texture.get_surface() gfxdraw.textured_polygon(surface, pos, texture, tx, ty) elif dtype == DECORATION_ARC: points, r, ia, fa, color, width, gfx, kwargs = data points = self._update_pos_list(rect, decoid, points, **kwargs) x, y = points[0] rectarc = pygame.Rect(x - r, y - r, x + 2 * r, y + 2 * r) if gfx: gfxdraw.arc(surface, x, y, r, ia, fa, color) else: pydraw.arc(surface, color, rectarc, ia / (2 * pi), fa / (2 * pi), width) elif dtype == DECORATION_PIE: points, r, ia, fa, color, kwargs = data points = self._update_pos_list(rect, decoid, points, **kwargs) x, y = points[0] gfxdraw.pie(surface, x, y, r, ia, fa, color) elif dtype == DECORATION_BEZIER: points, color, steps, kwargs = data points = self._update_pos_list(rect, decoid, points, **kwargs) gfxdraw.bezier(surface, points, steps, color) elif dtype == DECORATION_RECT: drect: 'pygame.Rect' pos, drect, color, width, kwargs = data pos = self._update_pos_list(rect, decoid, pos, **kwargs)[0] drect = drect.copy() drect.x += pos[0] drect.y += pos[1] pygame.draw.rect(surface, color, drect, width) elif dtype == DECORATION_PIXEL: pos, color, kwargs = data pos = self._update_pos_list(rect, decoid, pos, **kwargs)[0] gfxdraw.pixel(surface, pos[0], pos[1], color) elif dtype == DECORATION_LINE: pos, color, width, kwargs = data pos = self._update_pos_list(rect, decoid, pos, **kwargs) pydraw.line(surface, color, pos[0], pos[1], width) else: raise ValueError('unknown decoration type')
def draw_arc(screen, circle_midX, circle_midY, r, min_radius, start, end, color, thickness): for x in range(0, thickness): gfxdraw.arc(screen, circle_midX, circle_midY, r * thickness + x + min_radius, start, end, color)
def draw_arc(pos, r, bounds, color, global_coords=True): if global_coords: pos = world_to_win_pt(pos, c.player.center) gfxdraw.arc(screen, pos[0], pos[1], r, int(bounds[0]*180/math.pi), int(bounds[1]*180/math.pi), color)
def draw_arc(self, surface, center, radius, start_angle, stop_angle, color): x,y = center start_angle = int(start_angle%360) stop_angle = int(stop_angle%360) gfxdraw.arc(surface, x, y, radius, start_angle, stop_angle, color)