当前位置: 首页>>代码示例>>Python>>正文


Python Rect.union_ip方法代码示例

本文整理汇总了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()
开发者ID:jeamesbone,项目名称:N-Arcs,代码行数:27,代码来源:object.py

示例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()
开发者ID:HampshireCS,项目名称:cs143-Spring2012,代码行数:27,代码来源:menu.py

示例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
开发者ID:Grug16,项目名称:Save-the-Robots-Game,代码行数:41,代码来源:text.py

示例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 )
开发者ID:CTPUG,项目名称:pygame_cffi,代码行数:7,代码来源:rect_test.py

示例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))
开发者ID:bitcraft,项目名称:pyweek17,代码行数:78,代码来源:quadtree.py


注:本文中的pygame.Rect.union_ip方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。