def draw_ellipse(surface, p, width, color, line_width, center=True, filled=False): """Draw an antialiased isometric ellipse params: surface, Point, ellipse width in grid sizes (float), color tuple, line width (int) The ellipse is centered in p :returns: (width, height) of the bounding box """ gs = Get_Grid_Size() width_pix = width * gs if center: # center the ellipse c = p + Point(gs/2, gs/2) else: c = p if filled: w = width_pix height = int(w * .574) gfxdraw.filled_ellipse(surface, c.x, c.y, int(w), height, color) for x in xrange(line_width): w = width_pix + x height = int(w * .574) gfxdraw.aaellipse(surface, c.x, c.y, int(w), height, color) return int(w), height
def draw_circle(self, x, y, colour): gfxdraw.filled_ellipse(self.screen, int((x + 0.5) * self.hs), int((y + 0.5) * self.vs), self.hs / 2, self.vs / 2, colour) gfxdraw.aaellipse(self.screen, int((x + 0.5) * self.hs), int((y + 0.5) * self.vs), self.hs / 2, self.vs / 2, BLACK)
def fadingEllipse(rMaj, rMin, col=(0, 0, 1)): col = HtoR(*col) w = 2 * rMaj + 1 h = 2 * rMin + 1 sf = pg.Surface((w, h), flags=pg.SRCALPHA) for i in range(rMaj): pc = i / (rMaj) alpha = int(pc * 255) currMaj = int((1 - pc) * rMaj) currMin = int((1 - pc) * rMin) gfx.filled_ellipse(sf, rMaj, rMin, currMaj, currMin, (*col, alpha)) return sf
def draw(self, surface): WIDTH, HEIGHT = SIZE SIZE_H_X, SIZE_H_Y = SIZE_H ellipse_rects = [ # cx cy rx ry [WIDTH // 2, 0, WIDTH // 2, self.size], # Top [0, HEIGHT // 2, self.size, HEIGHT // 2], # Left [WIDTH // 2, HEIGHT, WIDTH // 2, self.size], # Bottom [WIDTH, HEIGHT // 2, self.size, HEIGHT // 2], # Right ] for col, rect in zip(self.colors, ellipse_rects): ellipse = tuple(map(int, rect)) if any(val < 0 for val in ellipse): continue gfxdraw.aaellipse(surface, *ellipse, col) gfxdraw.filled_ellipse(surface, *ellipse, col)
def render_raw(self, res: Tuple[int], frame: int) -> pygame.Surface: surface = pygame.Surface(res, pygame.SRCALPHA) loc = self.loc(frame) size = self.size(frame) color = self.color(frame) border = self.border(frame) border_color = self.border_color(frame) antialias = self.antialias(frame) if antialias: gfxdraw.aaellipse(surface, *loc, *size, color) gfxdraw.filled_ellipse(surface, *loc, *size, color) else: pygame.draw.ellipse(surface, color, loc + size) if border > 0: pygame.draw.ellipse(surface, border_color, loc + size, border) return surface
def _drawO(screen, screen_settings, pos, color=(255, 255, 255), bg_color=(0, 0, 0)): w = screen_settings.square_width h = screen_settings.square_height rx = screen_settings.square_width // 2 - int(0.15 * w) ry = screen_settings.square_height // 2 - int(0.15 * h) rx1 = rx - round(sqrt(2 * (int(0.22 * w) - int(0.15 * w))**2)) ry1 = ry - round(sqrt(2 * (int(0.22 * h) - int(0.15 * h))**2)) gfxdraw.aaellipse(screen, pos[0] * w + int(0.5 * w), pos[1] * h + int(0.5 * h), rx, ry, color) gfxdraw.filled_ellipse(screen, pos[0] * w + int(0.5 * w), pos[1] * h + int(0.5 * h), rx, ry, color) gfxdraw.aaellipse(screen, pos[0] * w + int(0.5 * w), pos[1] * h + int(0.5 * h), rx1, ry1, bg_color) gfxdraw.filled_ellipse(screen, pos[0] * w + int(0.5 * w), pos[1] * h + int(0.5 * h), rx1, ry1, bg_color)
def filled_ellipse(self, x, y, rx, ry, color): """内部が塗りつぶされた楕円を描画します. Parameters ---------- x : int 楕円の左上のx座標. y : int 楕円の左上のy座標. rx : int 描画される楕円の幅 ry : int 描画される楕円の高さ color : tuple of int 描画に使用される色を指定します. """ return gfx.filled_ellipse(self.pg.screen, x, y, rx, ry, color)
def shadow(self): """ Draw a shadow under the character""" gfxdraw.filled_ellipse(controls.SCREEN, self.rect.midbottom[0], self.rect.midbottom[1], self.width / 3, self.height / 8, (10, 10, 10, 220))
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_circle(self, x, y, colour): gfxdraw.filled_ellipse(self.screen, int((x + 0.5) * self.hs), int((y + 0.5) * self.vs), self.hs/2, self.vs/2, colour) gfxdraw.aaellipse(self.screen, int((x + 0.5) * self.hs), int((y + 0.5) * self.vs), self.hs/2, self.vs/2, BLACK)
def draw_person(self, x, y, step, colour): step = abs(step) dark_colour = self.darken(colour) light_colour = self.lighten(colour, amount=20) self.step(x, y, step, dark_colour) #back arm self.draw_arm(x, y, step, colour, front=False) #body gfxdraw.filled_ellipse(self.screen, x, y, self.hs/8, self.vs/4, colour) gfxdraw.aaellipse(self.screen, x, y, self.hs/8, self.vs/4, BLACK) #head if self.special: self.draw_hair(x, y - self.vs/3,colour) gfxdraw.filled_ellipse(self.screen, x, y - self.vs/3, self.hs/4, self.vs/7, light_colour) gfxdraw.aaellipse(self.screen, x, y - self.vs/3, self.hs/4, self.vs/7, BLACK) #creepy eyes gfxdraw.filled_ellipse(self.screen, x - self.hs/10, y - self.vs/3, self.hs/15, self.vs/15, WHITE) gfxdraw.aaellipse(self.screen, x - self.hs/10, y - self.vs/3, self.hs/15, self.vs/15, BLACK) gfxdraw.filled_ellipse(self.screen, x - self.hs/10, y - self.vs/3, self.hs/35, self.vs/35, BLACK) gfxdraw.filled_ellipse(self.screen, x + self.hs/10, y - self.vs/3, self.hs/15, self.vs/15, WHITE) gfxdraw.aaellipse(self.screen, x + self.hs/10, y - self.vs/3, self.hs/15, self.vs/15, BLACK) gfxdraw.filled_ellipse(self.screen, x + self.hs/10, y - self.vs/3, self.hs/35, self.vs/35, BLACK) self.draw_fringe(x, y - self.vs/3, colour) #front arm self.draw_arm(x, y, step, colour)
def draw_person(self, x, y, step, colour): step = abs(step) dark_colour = self.darken(colour) light_colour = self.lighten(colour, amount=20) self.step(x, y, step, dark_colour) #back arm self.draw_arm(x, y, step, colour, front=False) #body gfxdraw.filled_ellipse(self.screen, x, y, self.hs / 8, self.vs / 4, colour) gfxdraw.aaellipse(self.screen, x, y, self.hs / 8, self.vs / 4, BLACK) #head if self.special: self.draw_hair(x, y - self.vs / 3, colour) gfxdraw.filled_ellipse(self.screen, x, y - self.vs / 3, self.hs / 4, self.vs / 7, light_colour) gfxdraw.aaellipse(self.screen, x, y - self.vs / 3, self.hs / 4, self.vs / 7, BLACK) #creepy eyes gfxdraw.filled_ellipse(self.screen, x - self.hs / 10, y - self.vs / 3, self.hs / 15, self.vs / 15, WHITE) gfxdraw.aaellipse(self.screen, x - self.hs / 10, y - self.vs / 3, self.hs / 15, self.vs / 15, BLACK) gfxdraw.filled_ellipse(self.screen, x - self.hs / 10, y - self.vs / 3, self.hs / 35, self.vs / 35, BLACK) gfxdraw.filled_ellipse(self.screen, x + self.hs / 10, y - self.vs / 3, self.hs / 15, self.vs / 15, WHITE) gfxdraw.aaellipse(self.screen, x + self.hs / 10, y - self.vs / 3, self.hs / 15, self.vs / 15, BLACK) gfxdraw.filled_ellipse(self.screen, x + self.hs / 10, y - self.vs / 3, self.hs / 35, self.vs / 35, BLACK) self.draw_fringe(x, y - self.vs / 3, colour) #front arm self.draw_arm(x, y, step, colour)