本文整理汇总了Python中pygame.Rect.union_ip方法的典型用法代码示例。如果您正苦于以下问题:Python Rect.union_ip方法的具体用法?Python Rect.union_ip怎么用?Python Rect.union_ip使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pygame.Rect
的用法示例。
在下文中一共展示了Rect.union_ip方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: CircleUnionObject
# 需要导入模块: from pygame import Rect [as 别名]
# 或者: from pygame.Rect import union_ip [as 别名]
class CircleUnionObject(PhysicsObject):
def __init__(self,particle,color):
'''
Constructor
'''
PhysicsObject.__init__(self,particle)
self.rect = Rect(0,0,0,0)
for c in particle.collider.colliders:
radius = int(c.r)
rect = pygame.Rect(c.p.x-radius,c.p.y-radius,radius*2+1, radius*2+1)
self.rect.union_ip(rect)
self.original = pygame.surface.Surface([self.rect.width,self.rect.height],SRCALPHA)
for c in particle.collider.colliders:
radius = int(c.r)
x = int(c.p.x)
y = int(c.p.y)
pygame.gfxdraw.aacircle(self.original, x-self.rect.left,y-self.rect.top,radius,color)
pygame.gfxdraw.filled_circle(self.original,x-self.rect.left,y-self.rect.top,radius,color)
self.view = self.original
self.update()
示例2: build
# 需要导入模块: from pygame import Rect [as 别名]
# 或者: from pygame.Rect import union_ip [as 别名]
def build(self):
# calculate the max dimensions
max_w, max_h = 0, 0
for item in self.items:
width, height = self.font.size(item.text)
max_w = max(width, max_w)
max_h = max(height, max_h)
rect = Rect(0,0,max_w,max_h).inflate(self.padding, self.padding)
# place and initialize each menu item
bounds = Rect(0, 0, 0, 0)
top = 0
for item in self.items:
item.image = Surface(rect.size, SRCALPHA)
item.rect = rect.copy()
item.rect.top = top
top = item.rect.bottom + self.margin
bounds.union_ip(item.rect)
# tmp, render each sprite initially
for item in self.items:
item.draw_normal()
示例3: render
# 需要导入模块: from pygame import Rect [as 别名]
# 或者: from pygame.Rect import union_ip [as 别名]
def render(self, lines, antialias, fg, bg=None):
block = []
bounds = Rect(0,0,self.margin,self.margin)
for line in lines:
if bg is not None:
text = self.font.render(line, antialias, fg, bg)
else:
text = self.font.render(line, antialias, fg)
rect = text.get_rect()
if bounds.bottom > self.margin:
rect.top = bounds.bottom + self.padding
bounds.union_ip(rect)
block.append((text,rect))
bounds.height += self.margin
surf = Surface(bounds.size, SRCALPHA)
if bg is not None:
surf.fill(bg)
else:
surf.fill((0,0,0,0))
for line,rect in block:
if self.justify == LEFT:
rect.left = bounds.left + self.margin
elif self.justify == RIGHT:
rect.right = bounds.right - self.margin
elif self.justify == CENTER:
rect.centerx = bounds.centerx
surf.blit(line, rect)
return surf
示例4: test_union_ip
# 需要导入模块: from pygame import Rect [as 别名]
# 或者: from pygame.Rect import union_ip [as 别名]
def test_union_ip( self ):
r1 = Rect( 1, 1, 1, 2 )
r2 = Rect( -2, -2, 1, 2 )
r1.union_ip(r2)
self.assertEqual( Rect( -2, -2, 4, 5 ), r1 )
示例5: __init__
# 需要导入模块: from pygame import Rect [as 别名]
# 或者: from pygame.Rect import union_ip [as 别名]
def __init__(self, items, depth=4, bounding_rect=None):
"""Creates a quad-tree.
@param items:
A sequence of items to store in the quad-tree. Note that these
items must be a pygame.Rect or have a .rect attribute.
@param depth:
The maximum recursion depth.
@param bounding_rect:
The bounding rectangle of all of the items in the quad-tree. For
internal use only.
"""
# The sub-quadrants are empty to start with.
self.nw = self.ne = self.se = self.sw = None
# If we've reached the maximum depth then insert all items into this
# quadrant.
depth -= 1
if depth == 0 or not items:
self.items = items
return
# Find this quadrant's centre.
if bounding_rect:
bounding_rect = Rect( bounding_rect )
else:
# If there isn't a bounding rect, then calculate it from the items.
bounding_rect = Rect( items[0] )
for item in items[1:]:
bounding_rect.union_ip( item )
cx = self.cx = bounding_rect.centerx
cy = self.cy = bounding_rect.centery
self.items = []
nw_items = []
ne_items = []
se_items = []
sw_items = []
for item in items:
# Which of the sub-quadrants does the item overlap?
in_nw = item.left <= cx and item.top <= cy
in_sw = item.left <= cx and item.bottom >= cy
in_ne = item.right >= cx and item.top <= cy
in_se = item.right >= cx and item.bottom >= cy
# If it overlaps all 4 quadrants then insert it at the current
# depth, otherwise append it to a list to be inserted under every
# quadrant that it overlaps.
if in_nw and in_ne and in_se and in_sw:
self.items.append(item)
else:
if in_nw: nw_items.append(item)
if in_ne: ne_items.append(item)
if in_se: se_items.append(item)
if in_sw: sw_items.append(item)
# Create the sub-quadrants, recursively.
if nw_items:
self.nw = FastQuadTree(nw_items, depth, \
(bounding_rect.left, bounding_rect.top, cx, cy))
if ne_items:
self.ne = FastQuadTree(ne_items, depth, \
(cx, bounding_rect.top, bounding_rect.right, cy))
if se_items:
self.se = FastQuadTree(se_items, depth, \
(cx, cy, bounding_rect.right, bounding_rect.bottom))
if sw_items:
self.sw = FastQuadTree(sw_items, depth, \
(bounding_rect.left, cy, cx, bounding_rect.bottom))