def _draw_colored_polygon(self, surface, poly, color, zoom, translation, angle, clip=True): import pygame from pygame import gfxdraw poly = [pygame.math.Vector2(c).rotate_rad(angle) for c in poly] poly = [(c[0] * zoom + translation[0], c[1] * zoom + translation[1]) for c in poly] # This checks if the polygon is out of bounds of the screen, and we skip drawing if so. # Instead of calculating exactly if the polygon and screen overlap, # we simply check if the polygon is in a larger bounding box whose dimension # is greater than the screen by MAX_SHAPE_DIM, which is the maximum # diagonal length of an environment object if not clip or any( (-MAX_SHAPE_DIM <= coord[0] <= WINDOW_W + MAX_SHAPE_DIM) and (-MAX_SHAPE_DIM <= coord[1] <= WINDOW_H + MAX_SHAPE_DIM) for coord in poly): gfxdraw.aapolygon(self.surf, poly, color) gfxdraw.filled_polygon(self.surf, poly, color)
def render(surface, grid, height, width): for row in range(-1, height + 1): for col in range(-row, width + 1): color = colors[grid[row % height, col % width]] hexcenter = hexagon_tools.coordinates(row, col) points = hexagon_tools.vertices(hexcenter) filled_polygon(surface, points, color)
def draw(self): """ Draw menu to the active surface. :return: None """ self._frame += 1 # Draw background rectangle _gfxdraw.filled_polygon(self._surface, self._bgrect, self._bgcolor) # Update menu bar position self._menubar.set_position(self._posx, self._posy) self._menubar.draw(self._surface) # Draw options (widgets) for index in range(len(self._option)): widget = self._option[index] # Update widget position widget.set_position(*self._get_option_pos(index)) # Draw widget widget.draw(self._surface) # If selected item then draw a rectangle if self._drawselrect and widget.selected: widget.draw_selected_rect(self._surface, self._sel_color, self._selected_inflate_x, self._selected_inflate_y, self._rect_width)
def drawwood(self, time, settings, screen, scale, currentxscroll, bottomypos): shelfwidth = currentxscroll + screen.get_width() shelfheight = 7*scale shelfdepth = 18*scale shelfdepthoffset = 7*scale shelfyoffset = 2*scale frontcolor = (127, 88, 26) frontrect = Rect(-currentxscroll+10*scale, bottomypos-shelfheight+shelfyoffset, 80*scale, shelfheight) # draw depth depthplist = [(frontrect[0], frontrect[1]), (frontrect[0]+shelfdepthoffset, frontrect[1]-shelfheight), (frontrect[0]+frontrect.width+shelfdepthoffset, frontrect[1]-shelfheight), (frontrect[0]+frontrect.width, frontrect[1])] gfxdraw.filled_polygon(screen, depthplist, variables.brighten(frontcolor, 13)) # draw front gfxdraw.box(screen, frontrect, frontcolor) # draw right side rsideplist = [depthplist[-2], depthplist[-1], (frontrect[0]+frontrect.width, frontrect[1]+shelfheight), (depthplist[-2][0], depthplist[-2][1]+shelfheight)] gfxdraw.filled_polygon(screen, rsideplist, variables.brighten(frontcolor, -3))
def draw_road(self, frame, lane=1): self.road_view = pygame.Surface((1010, ROAD_HEIGHT), pygame.SRCALPHA, 32) self.road_view = self.road_view.convert_alpha() pygame.draw.polygon(self.road_view, COLOR['black'], [(-337.0 * lane + 673.33, ROAD_HEIGHT), (455, 0), (555, 0), (-336.67 * lane + 3032, ROAD_HEIGHT)]) left = -337.0 * lane + 673.33 for i in range(8): if i == 0 or i == 7: gfxdraw.filled_polygon(self.road_view, ((int(int(i * 100.0 / 7 + 455)), 0), (int(int(i * 100.0 / 7 + 455)) + 7, 0), (int(left) + 7, int(ROAD_HEIGHT)), (int(left), int(ROAD_HEIGHT))), COLOR['white']) else: draw_dashed_line_delay(self.road_view, COLOR['white'], (i * 100.0 / 7 + 455, 0), (left, ROAD_HEIGHT), width=5, dash_length=40, delay=frame % 3) left += 337.0 self.surface.blit(self.road_view, ((self.origin_x, self.origin_y), (self.width, self.height)))
def drawwood(self, time, settings, screen, scale, bottomypos, currentxscroll, endscroll): shelfheight = 7 * scale shelfdepth = 18 * scale shelfdepthoffset = 7 * scale shelfyoffset = 2 * scale frontcolor = (127, 88, 26) left = 10 * scale - currentxscroll shelfwidth = max(endscroll - scale * 10, screen.get_width() / 2) frontrect = Rect(left, bottomypos - shelfheight + shelfyoffset, shelfwidth, shelfheight) # draw depth depthplist = [(frontrect[0], frontrect[1]), (frontrect[0] + shelfdepthoffset, frontrect[1] - shelfheight), (frontrect[0] + frontrect.width + shelfdepthoffset, frontrect[1] - shelfheight), (frontrect[0] + frontrect.width, frontrect[1])] gfxdraw.filled_polygon(screen, depthplist, variables.brighten(frontcolor, 13)) # draw front gfxdraw.box(screen, frontrect, frontcolor) # draw right side rsideplist = [ depthplist[-2], depthplist[-1], (frontrect[0] + frontrect.width, frontrect[1] + shelfheight), (depthplist[-2][0], depthplist[-2][1] + shelfheight) ] gfxdraw.filled_polygon(screen, rsideplist, variables.brighten(frontcolor, -3))
def __init__(self, start_loc, size, speed, rot_speed, dir, depth, screen_size): self.loc = start_loc self.size = size self.radius = math.sqrt(3) * self.size / 3 # the radius of the circle the snowflake is inscribed in self._velocity = (0.0, 0.0) self._rot_speed = rot_speed self._dir = dir self.theta = 0 self.depth = depth self._velocity = [math.sin(self.theta) * self._dir, speed] self.wind = [0, 0] self._damping = 0.0001 # damping factor so wind dies down self.debug = False self._stroke_color = (0, 0, 0, 200) self._screen_size = screen_size blue = random.randrange(20) # how blue the snowflakes should be self._fill_color = (255 - blue, 255 - blue, 255, 240) points = self.generate_snowflake() self.surface = pygame.Surface((self.radius * 2, self.radius * 2), pygame.SRCALPHA, 32).convert_alpha() gfxdraw.aapolygon(self.surface, points, self._stroke_color) # border gfxdraw.filled_polygon(self.surface, points, self._fill_color) # fill gfxdraw.polygon(self.surface, points, self._stroke_color) # fill
def set_image(self, active): self.text_surface = self.font.render(self.caption, True, black if not active else gray) self.text = (self.text_surface, self.text_rect) self.image = pygame.Surface([self.w, self.h]) self.fill_with_outline(white, black if not active else gray) self.rect = self.image.get_rect() self.rect.center = (self.x, self.y) self.text[1].center = (self.rect.width // 2, self.rect.height // 2) if self.type == 'right_arrow': gfx.aapolygon( self.image, [[3 * self.w // 4, self.h // 2], [self.w // 4, self.h // 4], [self.w // 4, 3 * self.h // 4]], gray if active else black) gfx.filled_polygon( self.image, [[3 * self.w // 4, self.h // 2], [self.w // 4, self.h // 4], [self.w // 4, 3 * self.h // 4]], gray if active else black) elif self.type == 'left_arrow': gfx.aapolygon( self.image, [[self.w // 4, self.h // 2], [3 * self.w // 4, self.h // 4], [3 * self.w // 4, 3 * self.h // 4]], gray if active else black) gfx.filled_polygon( self.image, [[self.w // 4, self.h // 2], [3 * self.w // 4, self.h // 4], [3 * self.w // 4, 3 * self.h // 4]], gray if active else black) else: self.image.blit(self.text[0], self.text[1])
def draw_board(self, show_mcts_predictions: bool = True): counter = 0 for row in range(self.board_size): for column in range(self.board_size): self.draw_hexagon(self.screen, self.black, self.get_coordinates(row, column), counter) counter += 1 self.draw_text() # Filled polygons gradient-coloured based on MCTS predictions # (i.e. normalized #visits per node) if show_mcts_predictions: try: n = 6 for (row, column) in mcts_predictions.keys(): x, y = self.get_coordinates(row, column) gfxdraw.filled_polygon( self.screen, [(x + self.hex_radius * cos(radians(90) + 2 * pi * _ / n), y + self.hex_radius * sin(radians(90) + 2 * pi * _ / n)) for _ in range(n)], self.green + (mcts_predictions[(row, column)], )) except NameError: pass
def drawShapelyPolygon(onto, polygon, color): polygonPoints = [] for x, y in polygon.exterior.coords: polygonPoints.append((int(x), int(y))) gfxdraw.filled_polygon(onto, polygonPoints, color)
def draw(self, surface): self._render() if len(self._polygon_pos) > 2: gfxdraw.filled_polygon(surface, self._polygon_pos, self._background_color) # Draw backbox if enabled if self.mouse_enabled and self._backbox: # The following check belongs to the case if the menu displays a "x" button to close # the menu, but onclose Menu method is None (Nothing is executed), then the button will # not be displayed # noinspection PyProtectedMember if self._box_mode == _MODE_CLOSE and self.get_menu( )._onclose is None: pass else: pygame.draw.rect(surface, self._font_selected_color, self._backbox_rect, 1) pygame.draw.polygon(surface, self._font_selected_color, self._backbox_pos) surface.blit(self._surface, (self._rect.topleft[0] + self._offsetx, self._rect.topleft[1] + self._offsety))
def draw(self, pressed, shifted): if pressed is None: # Unused state (overwritten if binding exists) key_color = (50, 50, 50) txt_color = (80, 80, 80) elif pressed: key_color = (150, 150, 150) txt_color = (0, 0, 0) else: key_color = (50, 50, 50) txt_color = (250, 250, 250) points = [ [self.x, self.y], [self.x, self.y+self.height], [self.x+self.width, self.y+self.height], [self.x+self.width, self.y] ] points = [[int(round(x)) for x in xy] for xy in points] gfxdraw.filled_polygon(screen, points, key_color) gfxdraw.aapolygon(screen, points, key_color) font = pg.font.SysFont("monospace", 12) if shifted: name = self.shift else: name = self.name label = font.render(name, 1, txt_color) r = label.get_rect() center = [self.x+self.width/2, self.y+self.height/2] corner = [center[0]-r.width/2, center[1]-r.height/2] corner = [int(round(x)) for x in corner] screen.blit(label, corner)
def draw_colored_polygon(self, surface, poly, color, zoom, translation, angle): poly = [pygame.math.Vector2(c).rotate_rad(angle) for c in poly] poly = [(c[0] * zoom + translation[0], c[1] * zoom + translation[1]) for c in poly] gfxdraw.aapolygon(self.surf, poly, color) gfxdraw.filled_polygon(self.surf, poly, color)
def draw(self): """ Draw menu to surface. :return: None """ # Draw background rectangle _gfxdraw.filled_polygon(self._surface, self._bgrect, self._bgcolor) # Update menu bar position self._menubar.set_position(self._posx, self._posy) self._menubar.draw(self._surface) # Draw options for index in range(len(self._option)): widget = self._option[index] # Update widget position widget.set_position(*self._get_option_pos(index)) # Draw widget widget.draw(self._surface) # If selected item then draw a rectangle if self._drawselrect and widget.selected: rect = widget.get_rect() _pygame.draw.rect(self._surface, self._sel_color, rect.inflate(16, 4), self._rect_width)
def draw_dashed_line_delay(surf, color, start_pos, end_pos, width=1, dash_length=10, delay=0): if not config.VISUALENABLED: return origin = Point(start_pos) target = Point(end_pos) displacement = target - origin length = len(displacement) slope = displacement / length loop = length / dash_length origin = origin + (slope * delay * 10) for index in range(0, loop + 1, 2): start = origin + (slope * index * dash_length) end = origin + (slope * (index + 1) * dash_length) gfxdraw.filled_polygon(surf, ((int(start.x), int(start.y)), (int(start.x) + width, int(start.y)), (int(end.x) + width, int(end.y)), (int(end.x), int(end.y))), color)
def draw_variation_menu(self): if self.node.variations[1:]: try: coords = self.__get_var_menu_coords() for i, v, c in zip(itertools.count(), self.node.variations, coords): try: text = re.search(r"\((.+)\.\.\.\)", repr(v)).group(1) except Exception: text = "" color = ((0, 0, 0) if i != self.variation_menu_emphasis else (42, 42, 42)) gfx.filled_polygon(self.screen, c, color) try: self.render_text( text, (None, c[0][1] + 5), True, color # (None, y), ) except Exception as e: print(e) except AttributeError as e: self.stderr(e)
def draw(self, ctx): if self.isActive(): gfxdraw.filled_polygon(ctx, self.activeAngleCoords, self.color) gfxdraw.aapolygon(ctx, self.activeAngleCoords, self.color) else: gfxdraw.filled_polygon(ctx, self.angleCoords, self.color) gfxdraw.aapolygon(ctx, self.angleCoords, self.color)
def render_history_task(self, moves=None): """ Renders the history with autoscroll. To implement: * Move comments * Move marks eg. ! ? """ gfx.filled_polygon(self.screen, GUI.moves_panel, (21, 21, 21)) game = self.node.game() try: if moves is None: moves = self.__get_move_text_history(game, self.move, self.variation_path[1:]) except IndexError: moves = [] except Exception: self.exit() y = 80 move_amount = len(moves) if move_amount < 15: moves.extend([" " * 20] * (15 - move_amount)) elif 8 <= int(self.move) < move_amount - 8: b = int(self.move - 0.5) - 8 b = 0 if b < 0 else b moves = moves[b:int(self.move - 0.5) + 8] elif int(self.move) < 8: moves = moves[:15] moves = moves[-15:] for move in moves: # Highlight text if it is of the current move if move.startswith("\t"): b_left = GUI.moves_panel[0][0] b_right = GUI.moves_panel[1][0] # dy of -5 is needed to align the highlight dy = -5 rect = [ (b_left, y + dy), (b_right, y + dy), (b_right, y + dy + GUI.hist_slot_height), (b_left, y + dy + GUI.hist_slot_height), ] gfx.filled_polygon(self.screen, rect, (0, 0, 0)) self._initial_variation_y = y + dy self.render_text( move.lstrip(), (None, y), True, (0, 0, 0) if move.startswith("\t") else (21, 21, 21), ) y += GUI.hist_slot_height if "--always-variation" in sys.argv or self.display_variation_menu: self.draw_variation_menu() return moves
def draw_cell(cell): font_size = 16 virus_sizes = {100:1, 106:2, 113:3, 119:4, 125:5, 131:6, 136:7} cx,cy = world_to_win_pt(cell.pos,c.player.center) try: mov_ang = cell.movement_angle p2 = cell.pos + Vec( math.cos(mov_ang + mechanics.eject_delta*math.pi/180), math.sin(mov_ang + mechanics.eject_delta*math.pi/180) ) * (cell.size+700) p3 = cell.pos + Vec( math.cos(mov_ang - mechanics.eject_delta*math.pi/180), math.sin(mov_ang - mechanics.eject_delta*math.pi/180) ) * (cell.size+700) cx2,cy2 = world_to_win_pt(p2,c.player.center) cx3,cy3 = world_to_win_pt(p3,c.player.center) except (AttributeError, TypeError): cx2,cy2=cx,cy cx3,cy3=cx,cy radius = world_to_win_length(cell.size) if cell.is_virus: color = (0,255,0) color2 = (100,255,0) polygon = generate_virus(int(cell.size*0.3), 10*zoom, radius, (cx, cy)) polygon2 = generate_virus(int(cell.size*0.3), 10*zoom, radius-10, (cx, cy)) gfxdraw.filled_polygon(screen, polygon, color2) gfxdraw.polygon(screen, polygon, (0,0,0)) gfxdraw.aapolygon(screen, polygon, (0,0,0)) gfxdraw.filled_polygon(screen, polygon2, color) gfxdraw.aapolygon(screen, polygon2, color) draw_text((cx, cy), "%s / 7" % virus_sizes.get(cell.size, "?"), (64,0,0), font_size*2, False, True) draw_text((cx, cy + radius + 10), str(cell.cid), (0,0,0), font_size, False, True) else: color=(int(cell.color[0]*255), int(cell.color[1]*255), int(cell.color[2]*255)) if not (cell.is_ejected_mass or cell.is_food): gfxdraw.aapolygon(screen, [(cx,cy),(cx2,cy2),(cx3,cy3),(cx,cy)] ,(255,127,127)) gfxdraw.filled_circle(screen, cx, cy, radius, color) gfxdraw.aacircle(screen, cx, cy, radius, (0,0,0)) gfxdraw.aacircle(screen, cx, cy, int(radius/2), (255,255,255)) gfxdraw.circle(screen, cx, cy, int(radius/2), (255,255,255)) draw_text((cx, cy + radius + 10), cell.name, (0, 0, 0), font_size, False, True) draw_text((cx, cy + radius + 10 + font_size), str(cell.cid), (0,0,0), font_size, False, True) # surface = draw_text(cell.name, (0, 0, 0), font_size) # screen.blit(surface, (cx - (surface.get_width()/2), cy + radius + 5)) draw_text((cx, cy), str(int(cell.mass))+"/"+str(int(cell.size)), (255, 255, 255), font_size, False, True) # surface = draw_text(str(int(cell.mass)), (255, 255, 255), font_size) # screen.blit(surface, (cx - (surface.get_width()/2), cy - (surface.get_height()/2))) else: gfxdraw.aacircle(screen, cx, cy, radius, color) gfxdraw.filled_circle(screen, cx, cy, radius, color)
def draw_polygon(polygon, color, filled=False, global_coords=True): if len(polygon) > 2: if global_coords: polygon = list(map(lambda x: world_to_win_pt(x, c.player.center), polygon)) if filled: gfxdraw.filled_polygon(screen, polygon, color) else: gfxdraw.polygon(screen, polygon, color) gfxdraw.aapolygon(screen, polygon, color)
def drawPoly(view, transform, pointlist, lightlist, color = black, width = 0): lst = [ transform(p).xy() for p in pointlist ] draw.aalines(view.display, color, True, lst, True) #draw.polygon(view.display, color, lst, width) gfxdraw.filled_polygon(view.display, lst, color)
def displayStatus(statusMsg): """ Function to display the current status of the tool :param statusMsg: Status Message :return: """ gfxdraw.filled_polygon( screen, [[0, 0], [0, 24], [WINDOW_WIDTH, 24], [WINDOW_WIDTH, 0]], WHITE) status = myfont.render(statusMsg, 1, BLACK) screen.blit(status, (10, 10))
def draw(self, screen): h = screen.get_height() s = self.scale_sim_to_vis for wall in self.walls: pos = wall.position verts = wall.fixtures[0].shape.vertices verts = [(s * (pos.x + x), h - s * (pos.y + y)) for (x, y) in verts] gfxdraw.filled_polygon(screen, verts, self.wall_color)
def draw_arrow_head(x, y, angle, color, thickness): head_angle = math.pi / 6. width = 8 + thickness x -= width / 2. * math.cos(angle) y -= width / 2. * math.sin(angle) x1 = x + width * math.cos(angle + head_angle) y1 = y + width * math.sin(angle + head_angle) x2 = x + width * math.cos(angle - head_angle) y2 = y + width * math.sin(angle - head_angle) gfxdraw.aapolygon(surface, ((x, y), (x1, y1), (x2, y2)), color) gfxdraw.filled_polygon(surface, ((x, y), (x1, y1), (x2, y2)), color)
def displayLabel1(labelMsg): """ Function to display the options label line 1 :param labelMsg: options string :return: """ gfxdraw.filled_polygon(screen, [[0, WINDOW_HEIGHT - 30], [0, WINDOW_HEIGHT - 16], [WINDOW_WIDTH, WINDOW_HEIGHT - 16], [WINDOW_WIDTH, WINDOW_HEIGHT - 30]], WHITE) label1 = myfont.render(labelMsg, 1, BLACK) screen.blit(label1, (10, WINDOW_HEIGHT - 30))
def polygon(surf, points, color): """Draw an antialiased filled polygon on a surface""" gfxdraw.aapolygon(surf, points, color) gfxdraw.filled_polygon(surf, points, color) x = min([x for (x, y) in points]) y = min([y for (x, y) in points]) xm = max([x for (x, y) in points]) ym = max([y for (x, y) in points]) return pygame.Rect(x, y, xm - x, ym - y)
def render(self, screen, scale=None, anti_alias=False): if scale is None: scale = 1 if anti_alias: pointlist = [scale * self.flipy(x) for x in self.pointlist] gfxdraw.filled_polygon(screen, pointlist, pg.Color(self.color)) gfxdraw.aapolygon(screen, pointlist, pg.Color(self.color)) else: p1 = scale * self.flipy(self.start_pos) p2 = scale * self.flipy(self.end_pos) pg.draw.lines(screen, pg.Color(self.color), False, (p1, p2), int(scale * self.thickness))
def draw(self, surface, points, colors): color = colors[self.color_id] if color is None: return vertices = [points[v] for v in self.vertices] # pygame.draw # pygame.draw.polygon(surface, self.color, vertices, self.width) # pygame.gfxdraw aapolygon(surface, vertices, color) filled_polygon(surface, vertices, color)
def _draw(self, surface: 'pygame.Surface') -> None: if len(self._polygon_pos) > 2: gfxdraw.filled_polygon(surface, self._polygon_pos, self._background_color) # Draw backbox if enabled if self._backbox_visible(): # noinspection PyArgumentList pygame.draw.rect(surface, self._font_selected_color, self._backbox_rect, self._backbox_border_width) pygame.draw.polygon(surface, self._font_selected_color, self._backbox_pos) surface.blit(self._surface, (self._rect.topleft[0] + self._offsetx, self._rect.topleft[1] + self._offsety))
def draw(self, surface): self._render() if len(self._polygon_pos) > 2: gfxdraw.filled_polygon(surface, self._polygon_pos, self._background_color) if self.mouse_enabled and self._backbox: pygame.draw.rect(surface, self._font_selected_color, self._backbox_rect, 1) pygame.draw.polygon(surface, self._font_selected_color, self._backbox_pos) surface.blit(self._surface, (self._rect.topleft[0] + self._offsetx, self._rect.topleft[1] + self._offsety))
def percept(self, window): # find current theta theta = math.degrees(math.atan2(self.vel[1], self.vel[0])) if np.all( (self.vel != 0)) else 0 theta = circularize(theta) self.theta = theta # find points defining creature's view wrt theta points = fill_pie((int(self.pos[0]), int(self.pos[1])), self.sight, theta - self.view, theta + self.view, 20) # draw transparent sightline s = pygame.Surface((WIDTH, HEIGHT), pygame.SRCALPHA) gfxdraw.filled_polygon(s, points, (0, 255, 255, 150)) window.blit(s, (0, 0))
def draw(self): #Draws the centre hexagon gfxdraw.filled_polygon(screen,self.hexagonPoints,(15,75,0)) gfxdraw.aapolygon(screen,self.hexagonPoints,(25,220,0)) #environment.explosionSurface = Surface((960,540),SRCALPHA) #re declare the explosion surface for clearing (do to per-pixel alpha) environment.explosionSurface.fill((0,0,0,0)) for e in environment.explosionList: e.draw() #draws explosions e.manage() #makes explosions cool for a in self.asteroidList: a.draw() screen.blit(self.timeTxt(),(2,2))
def drawPolygon(origin, numpoints, points, color, filled): global gfxSurface points1 = [] noDraw = False for i in points: points1.append(getPoint(transformCoords(origin, i))) if getPoint(transformCoords(origin, i))[2] == 0: noDraw = True if filled: if not noDraw: gfxdraw.filled_polygon(gfxSurface, points1, color) if not filled: if not noDraw: gfxdraw.polygon(gfxSurface, points1, color)
def _drawTiles(self, surface: pygame.Surface) -> None: """ Draws the tiles on the given surface Args: surface: The surface on which the tiles will be drawn """ for i in range(len(self._drawMatrix)): for j in range(len(self._drawMatrix[0])): points = self._drawMatrix[i][j] internal_color = self._colorMatrix[i][j][self._INTERNAL_COLOR] border_color = self._colorMatrix[i][j][self._BORDER_COLOR] if internal_color is not None: gfxdraw.filled_polygon(surface, points, internal_color) gfxdraw.aapolygon(surface, points, border_color)
def render(self, screen, scale=None, anti_alias=False): if scale is None: scale = 1 pointlist = [] for v in self.vertices: x, y = pm.Vec2d(v).rotated(self.shape.body.angle) + self.shape.body.position point = scale * self.flipy([x, y]) pointlist.append([int(point[0]), int(point[1])]) if anti_alias: gfxdraw.filled_polygon(screen, pointlist, pg.Color(self.color)) gfxdraw.aapolygon(screen, pointlist, pg.Color(self.color)) else: pg.draw.polygon(screen, pg.Color(self.color), pointlist)
def displayNext(i): """ Display next step :param i: step number to be displayed :return: """ if i < len(triangles): gfxdraw.filled_polygon( screen, [triangles[i][0][:2], triangles[i][1][:2], triangles[i][2][:2]], RED) pygame.draw.polygon( screen, BLUE, [triangles[i][0][:2], triangles[i][1][:2], triangles[i][2][:2]], 1) pygame.draw.circle(screen, GREEN, ears[i][:2], 8)
def screen(self): if not self.first_opening: self.bg = self.scr.subsurface(self).copy() self.first_opening = True self.scr.fill(0x4d4c47,self) if self.item_index+self.offset>=0 and self.item_index+self.offset not in self.exc: self.scr.fill(0xe25817,(self.x,self.item_index*(self.item_h)+self.y-(self.top-self.itemsrect.top)%self.item_h,self.w,self.item_h)) b = self.itemsrect.y+self.margin//2 for e,i in enumerate(self.items): self.scr.blit(self.font.render(' %s '%(i.label if type(i)==Menu else i),1,(250,250,250)if e not in self.exc else(10,10,10)),(self.x,b)) if type(i)==Menu: r = pg.Rect(self.right-self.item_h,b-self.margin//2,self.item_h,self.item_h).inflate(-self.margin*3,-self.margin*3) filled_polygon(self.scr,(r.topleft,r.midright,r.bottomleft),(250,250,250)if e not in self.exc else(10,10,10)) aapolygon(self.scr,(r.topleft,r.midright,r.bottomleft),(250,250,250)if e not in self.exc else(10,10,10)) b+=self.item_h s = self.inflate(-2,-2) pg.draw.rect(self.scr,(100,100,100),self,1) pg.draw.lines(self.scr,(0,0,0),0,(s.topright,s.bottomright,s.bottomleft),1)
def draw(screen, now): w, h = screen.get_size() sunrise, noon, sunset = [((t - time.timezone) / 3600) % 12 for t in horology.sun_events(now, lon, lat)] local_now = now - time.timezone minutes = (local_now / 60) % 60 hours = (local_now / 3600) % 12 draw_dial(screen) xo = w // 2 yo = h // 2 ro = 0.04 * min(w, h) a = hours / 12 r = 0.22 * min(w, h) x, y = artoxy(a, r, xo, yo) points = (x, y), artoxy(a - 0.25, ro, xo, yo), artoxy(a + 0.25, ro, xo, yo) gfxdraw.filled_polygon(screen, points, fg) a = minutes / 60 r *= 1.61803 x, y = artoxy(a, r, xo, yo) points = (x, y), artoxy(a - 0.25, ro, xo, yo), artoxy(a + 0.25, ro, xo, yo) gfxdraw.filled_polygon(screen, points, fg) gfxdraw.filled_circle(screen, xo, yo, int(ro), fg) r = 0.25 * min(w, h) a = sunrise / 12 x, y = artoxy(a, r, xo, yo) gfxdraw.filled_circle(screen, x, y, int(0.25 * ro), fg) a = sunset / 12 x, y = artoxy(a, r, xo, yo) gfxdraw.filled_circle(screen, x, y, int(0.25 * ro), fg)
def __init__(self, surface): """ Инициализация. surface - поверхность на которой будем рисовать """ self.surface = surface self.surface.set_colorkey( C_BLACK, pygame.RLEACCEL ) self.rect = self.surface.get_rect() self.area = hex.Hex(self.hex_size, self.hex_dist) # Закрашенный гекс подсветки. self.solid = pygame.Surface( (self.area.S.size[0]+1, self.area.S.size[1]+1) ) self.solid.set_colorkey( C_BLACK, pygame.RLEACCEL ) self.solid.set_alpha(200, pygame.RLEACCEL) self.solid_rect = self.solid.get_rect() self.solid_rect.center = (-100,-100) points = self.area.polygon( (0,0) ) gfx.filled_polygon(self.solid, points, C_FILL) gfx.aapolygon(self.solid, points, C_WHITE) # Выбранный гекс. self.select = self.solid.copy() self.select_rect = self.select.get_rect() points = self.area.polygon( (0,0) ) gfx.filled_polygon(self.select, points, C_SELECT) gfx.aapolygon(self.select, points, C_WHITE) # отрисовка задника line = pygame.draw.line font = pygame.font.Font(None, 20) for i in range(self.hex_col): for j in range(self.hex_row): x, y = self.area.center( (i,j) ) points = self.area.polygon( (i,j) ) gfx.aapolygon(surface, points, C_WHITE) line(surface, C_WHITE, (x,y), (x,y), 1)#центральная точка text = font.render(str(i)+":"+str(j), 1, C_WHITE) surface.blit(text, (x,y))
def surface_with_node(surface, node, angle, offset_in, current_resize_offset, widthscalar, heightscalar): transformedlists = transformtopointlists(node.plantshapelist, node.shiftchance, angle, widthscalar, heightscalar) mainloffset = None mainltranslated = None def currentoffset(): return (offset_in[0] + current_resize_offset[0], offset_in[1] + current_resize_offset[1]) def surface_offset(pointlist_bounds): return Rect(currentoffset()[0]-node.anchor[0]+pointlist_bounds[0], currentoffset()[1]-node.anchor[1]+pointlist_bounds[1], pointlist_bounds.width, pointlist_bounds.height) # go through all the plantshapes and their corresponding transformed lists for i in range(len(transformedlists)): currentlist = transformedlists[i] bounds = getlistbounds(currentlist) # make the surface shape_surface = Surface((bounds.width, bounds.height), SRCALPHA) # translate points into this surface shiftedlist = offsetpointlist(currentlist, (-bounds[0], -bounds[1])) # draw the plant shape onto the new surface plantshape = node.plantshapelist[i] if plantshape.fillcolor != None: gfxdraw.filled_polygon(shape_surface, shiftedlist, plantshape.fillcolor) if plantshape.outlinecolor != None: gfxdraw.polygon(shape_surface, shiftedlist, plantshape.outlinecolor) # apply the texture if any for ptexture in plantshape.textures: addtexture(shape_surface, ptexture) # now check if resizing is needed newsurfacerect = surface.get_rect().union(surface_offset(bounds)) if not newsurfacerect == surface.get_rect(): new_surface = Surface((newsurfacerect.width, newsurfacerect.height), SRCALPHA) new_surface.blit(surface, (-newsurfacerect.x, -newsurfacerect.y)) current_resize_offset = (current_resize_offset[0]-newsurfacerect.x, current_resize_offset[1]-newsurfacerect.y) surface = new_surface devprint("Resized surface to " + str(new_surface.get_width()) + " by " + str(new_surface.get_height())) surface.blit(shape_surface, surface_offset(bounds)) # also save the first list for other nodes to go off of if i == 0: # save the offset of l without the resizing mainloffset = surface_offset(bounds) # also remove the current resize offset mainloffset = (mainloffset[0] - current_resize_offset[0], mainloffset[1]-current_resize_offset[1]) mainltranslated = shiftedlist return surface, mainltranslated, mainloffset, current_resize_offset
def drawAHat(surf, face): pointsInHat = [ (face.left, face.top), (face.left + face.width, face.top), (face.left + face.width/2, face.top - face.height/2 )] gfxdraw.filled_polygon(surf, pointsInHat, Color("red")) gfxdraw.aapolygon(surf, pointsInHat, Color("black"))
def _colorfill(self, surface, color, location): rect = self._tilerect(location) if surface.get_rect().contains(rect): image = surface.subsurface(rect) gfxdraw.filled_polygon(image, self._hex(), color)
color = [randint(0,255) for i in 1,2,3]+[50] while 1: ev = event.wait() if ev.type == MOUSEBUTTONDOWN and ev.button == 1: a.append([ev.pos]) c.append(color) if ev.type == MOUSEMOTION and ev.buttons[0]: a[-1].append(ev.pos) if len(a[-1]) >= 2: draw.aaline(scr,color,a[-1][-1],a[-1][-2],1) display.flip() if ev.type == MOUSEBUTTONUP and ev.button == 1: if len(a[-1]) >= 2: draw.aaline(scr,color,a[-1][0],a[-1][-1],1) gfxdraw.filled_polygon(scr,a[-1],color) display.flip() color = [randint(0,255) for i in 1,2,3]+[50] if ev.type == QUIT: break if ev.type == KEYDOWN and ev.key == K_s: p = PathGetter.get() if p: image.save(scr,p) if ev.type == KEYDOWN and ev.key == K_d and a: a.pop() c.pop() scr.fill(0) for lines,color in zip(a,c): draw.aalines(scr,color,1,lines,1) gfxdraw.filled_polygon(scr,lines,color) display.flip()
def _colortint(self, surface, color, location, alpha = None): rect = self._tilerect(location) image = Surface(rect.size, flags=SRCALPHA) gfxdraw.filled_polygon(image, self._hex(), (0, 0, 0, alpha or 128)) image.fill(color, special_flags=BLEND_ADD) surface.blit(image, rect.topleft)
def draw(self,screen): #apply transformation to x,y if needed tx,ty = self.x,self.y #calculate pts pts = [(tx,ty+self.diag/2),(tx+self.diag/2,ty),(tx,ty-self.diag/2),(tx-self.diag/2,ty)] gfxdraw.filled_polygon(screen,pts,color)