本文整理汇总了Python中pygame.draw.polygon函数的典型用法代码示例。如果您正苦于以下问题:Python polygon函数的具体用法?Python polygon怎么用?Python polygon使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了polygon函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __draw_walls
def __draw_walls(self):
closed = [(x,y) for y in range(len(self.matrix)) for x in range(len(self.matrix[0]))
if not self.matrix[y][x]]
for c in closed:
x, y = c2r(c)
draw.polygon(self.window, (100, 50, 50),
[(x,y), (x + X_CELL, y), (x + X_CELL, y + Y_CELL), (x, y + Y_CELL)])
示例2: paint
def paint(self, surface):
if not self.active:
return
point_list = self.get_points()
converted_point_list = []
for point in point_list:
converted_point_list.append(point.pair())
draw.polygon(surface, self.color, converted_point_list)
示例3: __draw_menu_cursor
def __draw_menu_cursor(self, surface):
cursor_height = self.menu_items_pos[self.selected_index]
draw.polygon(surface, self.orange_color, [
(400, cursor_height),
(400, cursor_height + self.cursor * 2),
(400 + self.cursor, cursor_height + self.cursor)])
draw.polygon(surface, self.orange_color, [
(780, cursor_height),
(780, cursor_height + self.cursor * 2),
(780 - self.cursor, cursor_height + self.cursor)])
示例4: draw_arrows
def draw_arrows(self, surf, i, rect):
m = self.margin
color = self.sel_color or self.fg_color
x, y = rect.midtop
pts = [(x - m, y - m), (x + m, y - m), (x, y)]
draw.polygon(surf, color, pts)
x, y = rect.midbottom
y -= 1
pts = [(x - m, y + m), (x + m, y + m), (x, y)]
draw.polygon(surf, color, pts)
示例5: draw_item
def draw_item(self, item):
if item.role == "Woger":
#if hasattr(item, 'image'):
#self.window.display_surface.blit(
# item.image, self.camera.point_to_screen(item.body.position))
if item.body.velocity[0] < -0.1:
self.window.display_surface.blit(
item.image[0], self.camera.point_to_screen(item.body.position))
self.facing_right = 0
elif item.body.velocity[0] > 0.1:
self.window.display_surface.blit(
item.image[1], self.camera.point_to_screen(item.body.position))
self.facing_right = 1
else:
self.window.display_surface.blit(
item.image[self.facing_right], self.camera.point_to_screen(item.body.position))
elif item.role == "Bough":
#an_image = item.image[angle(item.body.angle)]
#Only 16 images in there. So we find the closest image for that angle.
# >>> 360 / 23
# 15
# >>> 0 / 23
# 0
# >>> 180 / 23
# 7
assert(len(item.image) == 16)
idx_for_angle = int(angle(item.body.angle) /23)
an_image = item.image[idx_for_angle]
## verts = item.shape.get_points()
## x,y = sum(v[0] for v in verts)/3, sum(v[1] for v in verts)/3
self.window.display_surface.blit(an_image,
## self.camera.point_to_screen((x,y)))
self.camera.point_to_screen(item.body.position))
elif item.role == "Owange":
if item.status == "Collided":
self.window.display_surface.blit(
item.image[0], self.camera.point_to_screen(item.body.position))
else:
self.window.display_surface.blit(
item.image[0], self.camera.point_to_screen(item.body.position))
elif item.role == "Cherry":
self.window.display_surface.blit(
item.image[0], self.camera.point_to_screen(item.body.position))
else:
# note: 80% of program execution time is in this clause
# particularly retrieving the item.verts
draw.polygon(
self.window.display_surface,
item.color,
self.camera.to_screen(item.verts), 0)
示例6: redraw
def redraw(self):
self.pointlist = []
self.heights = []
if not self.pointlist:
self.generate_terrain(self.buffer.get_size())
if self.color:
draw.polygon(self.buffer, white, self.pointlist)
else:
draw.polygon(self.buffer, black, self.pointlist)
draw.lines(self.buffer, white, True, self.pointlist)
示例7: __draw_view_cells
def __draw_view_cells(self, obj):
color = obj.color
if obj.mode is 'hunting':
color = (255, obj.color[1], obj.color[2])
for point in obj.view_cells:
tl = c2r(point)
tr = tl[0] + X_CELL, tl[1]
br = tr[0], tr[1] + Y_CELL
bl = br[0] - X_CELL, br[1]
draw.polygon(self.window, color, (tl, tr, br, bl), 1)
示例8: render
def render(surface):
from pygame import draw
pts = []
gl.rotate(1.0/180*math.pi, 0.5 , 1 , 0.25);
#for pt in [(-160,-120,0),(-160,120,0),(160,120,0),(160,-120,0)]:
z = 0
for pt in [(-160,-120,z),(-160,120,z),(160,120, z),(160,-120, z)]:
tp = gl.trans_(pt);
# 画面の中心に移動
tp[0]+=320;
tp[1]+=240;
pts.append(tp);
draw.polygon(surface, (255,255,255), pts)
示例9: runGUI
def runGUI():
pygame.display.set_mode((800,600))
pygame.display.set_caption("Neuro Junk 2012/13")
screen = pygame.display.get_surface()
while True:
input(pygame.event.get())
screen.fill((0,0,0))
circle(screen, (255,255,255), (0,0), radius, 1)
line(screen, (255,255,255), point1, point2, 1)
polygon(screen, (255,255,255), outer_line, 2)
polygon(screen, (255,255,255), inner_line,2)
if intersectCircle(point1, point2, radius):
rect(screen, (0,255,0), Rect(600, 200, 100, 100), 0)
inn = changeField(inner_line, car)
out = changeField(outer_line, car)
csect = curSection(inn, out)
polygon(screen, (0,0,255), out, 2)
polygon(screen, (0,0,255), inn, 2)
rect(screen, (255,255,255), Rect(car.x-2, car.y-2, 4, 4), 0)
if csect is not None:
line(screen, (0,255,0), csect.inner_start, csect.inner_end, 1)
line(screen, (0,255,0), csect.outer_start, csect.outer_end, 1)
pygame.display.update()
示例10: draw_poly
def draw_poly(poly):
polygon = Polygon(poly.points)
if poly.orientation:
c = polygon.centroid.coords[0]
polygon = Polygon([rotate(p, c, -poly.orientation)
for p in polygon.exterior.coords])
c = polygon.centroid.coords[0]
p = poly.position
dx, dy = [p[i] - c[i] for i in range(2)]
draw.polygon(screen, (0,255,0),
[defloat(scale(offset(p, dx, dy)))
for p in polygon.exterior.coords],
1)
draw.circle(screen, (0,255,0),
defloat(scale(offset(c, dx, dy))),
3)
示例11: draw
def draw(self, screen):
halfw = self.width / 2
halfh = self.height / 2
x = self.x
y = self.y
# 1 4
# x
# 2 3
slope = 15
points = None
if self.side == Sides.LEFT:
points = (
(x - halfw, y + halfh + slope),
(x + halfw, y + halfh),
(x + halfw, y - halfh),
(x - halfw, y - halfh - slope)
)
elif self.side == Sides.RIGHT:
points = (
(x + halfw, y + halfh + slope),
(x - halfw, y + halfh),
(x - halfw, y - halfh),
(x + halfw, y - halfh - slope)
)
elif self.side == Sides.TOP:
points = (
(x - halfw - slope, y - halfh),
(x - halfw, y + halfh),
(x + halfw, y + halfh),
(x + halfw + slope, y - halfh)
)
elif self.side == Sides.BOT:
points = (
(x - halfw - slope, y + halfh),
(x - halfw, y - halfh),
(x + halfw, y - halfh),
(x + halfw + slope, y + halfh)
)
draw.polygon(
screen,
self.color,
points
)
示例12: _draw_base
def _draw_base(self):
img = self._images["image"]
img.fill(self._parent_view._settings["col"])
img.fill((200,200,200), self.rect.inflate(-4, -4))
# Draw line in center
r = self.rect
start_pos = (3, r.centery) if self.xy == "y" else (r.centerx, 3)
end_pos = (r.w-4, r.centery) if self.xy == "y" else (r.centerx, r.h-4)
draw.line(img, (100,100,100), start_pos, end_pos)
# Draw arrows
if self.xy == "y":
points1 = ((3, r.h/4), (r.centerx, r.h/5-1), (r.w-3, r.h/4))
points2 = ((3, r.h*.75), (r.centerx, r.h*.8), (r.w-3, r.h*.75))
else:
points1 = ((r.w/4, 3), (r.w/5-1, r.centery), (r.w/4, r.h-3))
points2 = ((r.w*.75, 3), (r.w*.8, r.centery), (r.w*.75, r.h-3))
draw.polygon(img, (50,50,50), points1)
draw.polygon(img, (50,50,50), points2)
示例13: draw_poly
def draw_poly(poly, surface, color=None, width=None):
polygon = orient_polygon(poly)
c = polygon.centroid.coords[0]
p = poly.position
dx, dy = [p[i] - c[i] for i in range(2)]
if color is None:
color = (0,255,0)
if width is None:
width = 1
draw.polygon(surface, color,
[defloat(scale(offset(p, dx, dy)))
for p in polygon.exterior.coords],
width)
if width:
draw.circle(surface, color,
defloat(scale(offset(c, dx, dy))),
3*width)
示例14: _draw_base
def _draw_base(self):
# Frames around edge of button
x = min(self.image.get_size()) / 8
self._frame_lt = ((0,0), (self.rect.w,0), (self.rect.w-x,x),
(x,x), (x,self.rect.h-x), (0,self.rect.h))
self._frame_rb = ((self.rect.w,self.rect.h),
(0,self.rect.h), (x,self.rect.h-x),
(self.rect.w-x,self.rect.h-x),
(self.rect.w-x,x), (self.rect.w,0))
cols = {}
cols["image"] = self._settings["col"]
cols["over"] = [min(c*1.1, 255) for c in self._settings["col"]]
cols["down"] = [c*0.8 for c in self._settings["col"]]
for img in cols:
self._images[img].fill(cols[img])
# Draw a frame around the edges of the button
frame_lt_c = [min(c*1.3,255) for c in cols[img]]
frame_rb_c = [c*0.8 for c in cols[img]]
draw.polygon(self._images[img], frame_lt_c, self._frame_lt)
draw.polygon(self._images[img], frame_rb_c, self._frame_rb)
示例15: _draw_shape_filled
def _draw_shape_filled(surface, shape):
"""Draw the shape on the given surface.
Arguments:
surface - drawing surface (an instance of pygame.Surface class);
shape - shape to draw (an instance of one of the shape classes
defined in shapes module);
Result:
bounding box, defined during the drawing;
"""
return draw.polygon(surface, SHAPE_COLOR, shape.get_vertices())