當前位置: 首頁>>代碼示例>>Python>>正文


Python pygame.gfxdraw方法代碼示例

本文整理匯總了Python中pygame.gfxdraw方法的典型用法代碼示例。如果您正苦於以下問題:Python pygame.gfxdraw方法的具體用法?Python pygame.gfxdraw怎麽用?Python pygame.gfxdraw使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在pygame的用法示例。


在下文中一共展示了pygame.gfxdraw方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: draw_bounds

# 需要導入模塊: import pygame [as 別名]
# 或者: from pygame import gfxdraw [as 別名]
def draw_bounds(screen,origin,screensize,angles):
    n_az = len(angles)
    radius = int(screensize[1]*.5)-10
    width = int(2)
    color = BLUE
    x, y, r = origin[0], origin[1], radius
    boundary = pygame.gfxdraw.aacircle(screen, x, y, r, color)
    #boundary = pygame.draw.circle(screen, color, origin, radius, width)

    # draw a bunch of lines
    radian_sweep = 2*math.pi / n_az
    radian_start = -0.5*radian_sweep
    for i in range(n_az):               # draw a bunch of bounds
        rad = radian_start + i*radian_sweep
        startpos = origin
        endpos = (int(origin[0]-radius*math.sin(rad)), int(origin[1]+radius*math.cos(rad)))
        pygame.draw.line(screen, color, startpos, endpos)
    return 
開發者ID:drscotthawley,項目名稱:panotti,代碼行數:20,代碼來源:headgames.py

示例2: draw_bars

# 需要導入模塊: import pygame [as 別名]
# 或者: from pygame import gfxdraw [as 別名]
def draw_bars(self, surface, rect):
        #pygame.draw.rect(surface, 
        width, height = rect.size
        
        color1 = self.color
        color2 = (0, 80, 110, 128)
        color3 = (255, 190, 50, 255)
        
        points = []
        
        for x, size in zip(range(25, width-15, 50), self.points):
            points.append( (x, size) )
            
        import pygame.gfxdraw
        
        for p1, p2 in zip(points, points[1:]):
            pygame.gfxdraw.line(surface, *p1, *p2, color2)
        
        for x, y in points:
            pygame.draw.rect(surface, color3, (x-2, y-2, 4, 4), 0) 
            #pygame.gfxdraw.circle(surface, color1, (x, y), 10, 1) 
            pygame.gfxdraw.aacircle(surface, x, y, 10, color1) 
開發者ID:furas,項目名稱:python-examples,代碼行數:24,代碼來源:main.py

示例3: main

# 需要導入模塊: import pygame [as 別名]
# 或者: from pygame import gfxdraw [as 別名]
def main():
    pygame.init()
    screen = pygame.display.set_mode((500,500))
    screen.fill((255, 0, 0))
    s = pygame.Surface(screen.get_size(), pygame.SRCALPHA, 32)
    pygame.draw.line(s, (0,0,0), (250, 250), (250+200,250))

    width = 1
    for a_radius in range(width):
        radius = 200
        pygame.gfxdraw.aacircle(s, 250, 250, radius-a_radius, (0, 0, 0))

    screen.blit(s, (0, 0))
    pygame.display.flip()
    try:
        while 1:
            event = pygame.event.wait()
            if event.type == pygame.QUIT:
                break
            if event.type == pygame.KEYDOWN:
                if event.key == pygame.K_ESCAPE or event.unicode == 'q':
                    break
            pygame.display.flip()
    finally:
        pygame.quit() 
開發者ID:wistbean,項目名稱:fxxkpython,代碼行數:27,代碼來源:aacircle.py

示例4: test_hline

# 需要導入模塊: import pygame [as 別名]
# 或者: from pygame import gfxdraw [as 別名]
def test_hline(self):
        """hline(surface, x1, x2, y, color): return None"""
        fg = self.foreground_color
        bg = self.background_color
        startx = 10
        stopx = 80
        y = 50
        fg_test_points = [(startx, y), (stopx, y), ((stopx - startx) // 2, y)]
        bg_test_points = [(startx - 1, y), (stopx + 1, y),
                          (startx, y - 1), (startx, y + 1),
                          (stopx, y - 1), (stopx, y + 1)]
        for surf in self.surfaces:
            fg_adjusted = surf.unmap_rgb(surf.map_rgb(fg))
            bg_adjusted = surf.unmap_rgb(surf.map_rgb(bg))
            pygame.gfxdraw.hline(surf, startx, stopx, y, fg)
            for posn in fg_test_points:
                self.check_at(surf, posn, fg_adjusted)
            for posn in bg_test_points:
                self.check_at(surf, posn, bg_adjusted) 
開發者ID:wistbean,項目名稱:fxxkpython,代碼行數:21,代碼來源:gfxdraw_test.py

示例5: test_vline

# 需要導入模塊: import pygame [as 別名]
# 或者: from pygame import gfxdraw [as 別名]
def test_vline(self):
        """vline(surface, x, y1, y2, color): return None"""
        fg = self.foreground_color
        bg = self.background_color
        x = 50
        starty = 10
        stopy = 80
        fg_test_points = [(x, starty), (x, stopy), (x, (stopy - starty) // 2)]
        bg_test_points = [(x, starty - 1), (x, stopy + 1),
                          (x - 1, starty), (x + 1, starty),
                          (x - 1, stopy), (x + 1, stopy)]
        for surf in self.surfaces:
            fg_adjusted = surf.unmap_rgb(surf.map_rgb(fg))
            bg_adjusted = surf.unmap_rgb(surf.map_rgb(bg))
            pygame.gfxdraw.vline(surf, x, starty, stopy, fg)
            for posn in fg_test_points:
                self.check_at(surf, posn, fg_adjusted)
            for posn in bg_test_points:
                self.check_at(surf, posn, bg_adjusted) 
開發者ID:wistbean,項目名稱:fxxkpython,代碼行數:21,代碼來源:gfxdraw_test.py

示例6: test_line

# 需要導入模塊: import pygame [as 別名]
# 或者: from pygame import gfxdraw [as 別名]
def test_line(self):
        """line(surface, x1, y1, x2, y2, color): return None"""
        fg = self.foreground_color
        bg = self.background_color
        x1 = 10
        y1 = 15
        x2 = 92
        y2 = 77
        fg_test_points = [(x1, y1), (x2, y2)]
        bg_test_points = [(x1 - 1, y1), (x1, y1 - 1), (x1 - 1, y1 - 1),
                          (x2 + 1, y2), (x2, y2 + 1), (x2 + 1, y2 + 1)]
        for surf in self.surfaces:
            fg_adjusted = surf.unmap_rgb(surf.map_rgb(fg))
            bg_adjusted = surf.unmap_rgb(surf.map_rgb(bg))
            pygame.gfxdraw.line(surf, x1, y1, x2, y2, fg)
            for posn in fg_test_points:
                self.check_at(surf, posn, fg_adjusted)
            for posn in bg_test_points:
                self.check_at(surf, posn, bg_adjusted) 
開發者ID:wistbean,項目名稱:fxxkpython,代碼行數:21,代碼來源:gfxdraw_test.py

示例7: test_trigon

# 需要導入模塊: import pygame [as 別名]
# 或者: from pygame import gfxdraw [as 別名]
def test_trigon(self):
        """trigon(surface, x1, y1, x2, y2, x3, y3, color): return None"""
        fg = self.foreground_color
        bg = self.background_color
        x1 = 10
        y1 = 15
        x2 = 92
        y2 = 77
        x3 = 20
        y3 = 60
        fg_test_points = [(x1, y1), (x2, y2), (x3, y3)]
        bg_test_points = [(x1 - 1, y1 - 1),
                          (x2 + 1, y2 + 1),
                          (x3 - 1, y3 + 1),
                          (x1 + 10, y1 + 30)]
        for surf in self.surfaces:
            fg_adjusted = surf.unmap_rgb(surf.map_rgb(fg))
            bg_adjusted = surf.unmap_rgb(surf.map_rgb(bg))
            pygame.gfxdraw.trigon(surf, x1, y1, x2, y2, x3, y3, fg)
            for posn in fg_test_points:
                self.check_at(surf, posn, fg_adjusted)
            for posn in bg_test_points:
                self.check_at(surf, posn, bg_adjusted) 
開發者ID:wistbean,項目名稱:fxxkpython,代碼行數:25,代碼來源:gfxdraw_test.py

示例8: test_filled_trigon

# 需要導入模塊: import pygame [as 別名]
# 或者: from pygame import gfxdraw [as 別名]
def test_filled_trigon(self):
        """filled_trigon(surface, x1, y1, x2, y2, x3, y3, color): return None"""
        fg = self.foreground_color
        bg = self.background_color
        x1 = 10
        y1 = 15
        x2 = 92
        y2 = 77
        x3 = 20
        y3 = 60
        fg_test_points = [(x1, y1), (x2, y2), (x3, y3),
                          (x1 + 10, y1 + 30)]
        bg_test_points = [(x1 - 1, y1 - 1),
                          (x2 + 1, y2 + 1),
                          (x3 - 1, y3 + 1)]
        for surf in self.surfaces:
            fg_adjusted = surf.unmap_rgb(surf.map_rgb(fg))
            bg_adjusted = surf.unmap_rgb(surf.map_rgb(bg))
            pygame.gfxdraw.filled_trigon(surf, x1, y1, x2, y2, x3, y3, fg)
            for posn in fg_test_points:
                self.check_at(surf, posn, fg_adjusted)
            for posn in bg_test_points:
                self.check_at(surf, posn, bg_adjusted) 
開發者ID:wistbean,項目名稱:fxxkpython,代碼行數:25,代碼來源:gfxdraw_test.py

示例9: test_bezier

# 需要導入模塊: import pygame [as 別名]
# 或者: from pygame import gfxdraw [as 別名]
def test_bezier(self):
        """bezier(surface, points, steps, color): return None"""
        fg = self.foreground_color
        bg = self.background_color
        points = [(10, 50), (25, 15), (60, 80), (92, 30)]
        fg_test_points = [points[0], points[3]]
        bg_test_points = [(points[0][0] - 1, points[0][1]),
                          (points[3][0] + 1, points[3][1]),
                          (points[1][0], points[1][1] + 3),
                          (points[2][0], points[2][1] - 3)]
        for surf in self.surfaces:
            fg_adjusted = surf.unmap_rgb(surf.map_rgb(fg))
            bg_adjusted = surf.unmap_rgb(surf.map_rgb(bg))
            pygame.gfxdraw.bezier(surf, points, 30, fg)
            for posn in fg_test_points:
                self.check_at(surf, posn, fg_adjusted)
            for posn in bg_test_points:
                self.check_at(surf, posn, bg_adjusted) 
開發者ID:wistbean,項目名稱:fxxkpython,代碼行數:20,代碼來源:gfxdraw_test.py

示例10: test_aatrigon

# 需要導入模塊: import pygame [as 別名]
# 或者: from pygame import gfxdraw [as 別名]
def test_aatrigon(self):
        """aatrigon(surface, x1, y1, x2, y2, x3, y3, color): return None"""
        fg = self.foreground_color
        bg = self.background_color
        x1 = 10
        y1 = 15
        x2 = 92
        y2 = 77
        x3 = 20
        y3 = 60
        fg_test_points = [(x1, y1), (x2, y2), (x3, y3)]
        bg_test_points = [(x1 - 1, y1 - 1),
                          (x2 + 1, y2 + 1),
                          (x3 - 1, y3 + 1),
                          (x1 + 10, y1 + 30)]
        for surf in self.surfaces:
            fg_adjusted = surf.unmap_rgb(surf.map_rgb(fg))
            bg_adjusted = surf.unmap_rgb(surf.map_rgb(bg))
            pygame.gfxdraw.aatrigon(surf, x1, y1, x2, y2, x3, y3, fg)
            for posn in fg_test_points:
                self.check_not_at(surf, posn, bg_adjusted)
            for posn in bg_test_points:
                self.check_at(surf, posn, bg_adjusted) 
開發者ID:wistbean,項目名稱:fxxkpython,代碼行數:25,代碼來源:gfxdraw_test.py

示例11: set_progress

# 需要導入模塊: import pygame [as 別名]
# 或者: from pygame import gfxdraw [as 別名]
def set_progress(self, percent, caption = ""):
        for event in pygame.event.get():
            if event.type == 12 and self.abortable:
                pygame.quit()
                import sys
                sys.exit()
        if caption:
            pygame.display.set_caption(caption)
        self.progress = percent
        self.surface.fill(self.bg)
        self.rect.width = self.progress*self.scale
        pygame.gfxdraw.box(self.surface, self.rect, self.fg)
        pygame.display.update(self.rect) 
開發者ID:Berserker66,項目名稱:omnitool,代碼行數:15,代碼來源:loadbar.py

示例12: _helper

# 需要導入模塊: import pygame [as 別名]
# 或者: from pygame import gfxdraw [as 別名]
def _helper(surf, color, rect, r):
    for x, y in [(rect[0] + r, rect[1] + r),
                 (rect[0] + rect[2] - r - 1, rect[1] + r),
                 (rect[0] + r, rect[1] + rect[3] - r - 1),
                 (rect[0] + rect[2] - r - 1, rect[1] + rect[3] - r - 1)]:
        pygame.gfxdraw.aacircle(surf, x, y, r, color)
        pygame.gfxdraw.filled_circle(surf, x, y, r, color)
    
    pygame.draw.rect(surf, color, (rect[0] + r, rect[1], rect[2] - 2*r, rect[3]))
    pygame.draw.rect(surf, color, (rect[0], rect[1] + r, rect[2], rect[3] - 2*r)) 
開發者ID:ankith26,項目名稱:My-PyChess,代碼行數:12,代碼來源:utils.py

示例13: draw

# 需要導入模塊: import pygame [as 別名]
# 或者: from pygame import gfxdraw [as 別名]
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)) 
開發者ID:ppizarror,項目名稱:pygame-menu,代碼行數:15,代碼來源:menubar.py

示例14: draw_head

# 需要導入模塊: import pygame [as 別名]
# 或者: from pygame import gfxdraw [as 別名]
def draw_head(screen,origin,screensize):
    color=DARKGREY
    cx, cy, scale  = origin[0],origin[1], int(screensize[1]/4)
    headsize = (int(scale*2/3),scale)
    rx, ry = int(headsize[0]/2), int(headsize[1]/2)

    #ears
    color=BLACK
    earw, earh = scale/10, scale/4
    earrx, earry = int(scale/20), int(scale/8)
    pygame.gfxdraw.filled_ellipse(screen, cx-rx, cy, earrx, earry, color)
    pygame.gfxdraw.aaellipse(screen, cx-rx, cy, earrx, earry, color)
    pygame.gfxdraw.filled_ellipse(screen, cx+rx, cy, earrx, earry, color)
    pygame.gfxdraw.aaellipse(screen, cx+rx, cy, earrx, earry, color)


    # head proper
    color = DARKGREY

    headbox = (cx-headsize[0]/2, int(cy-scale/2), headsize[0], headsize[1])
    pygame.gfxdraw.filled_ellipse(screen, cx, cy, rx, ry, color)
    pygame.gfxdraw.aaellipse(screen, cx, cy, rx, ry, color)
    #head = pygame.draw.ellipse(screen, color, headbox)
    #nose
    noserad = int(scale/15)
    nose = pygame.draw.circle(screen, color, (cx,int(headbox[1]+noserad/4)), noserad  )
    return 
開發者ID:drscotthawley,項目名稱:panotti,代碼行數:29,代碼來源:headgames.py

示例15: draw_gfxcircle

# 需要導入模塊: import pygame [as 別名]
# 或者: from pygame import gfxdraw [as 別名]
def draw_gfxcircle(self, x, y):
        p = self.pixel_size
        w_x = int(x * p + self.pixel_size / 2)
        w_y = int((self.height - 1 - y) * p + self.pixel_size / 2)
        r = int(self.pixel_size / 4)
        color = self.pixels[self.index(x, y)]
        pygame.gfxdraw.aacircle(self.screen, w_x, w_y, r, color)
        pygame.gfxdraw.filled_circle(self.screen, w_x, w_y, r, color) 
開發者ID:jayniz,項目名稱:unicorn-hat-sim,代碼行數:10,代碼來源:__init__.py


注:本文中的pygame.gfxdraw方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。