Python pygame.gfxdraw() Examples

The following are 30 code examples of pygame.gfxdraw(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module pygame , or try the search function .
Example #1
Source File: headgames.py    From panotti with MIT License 7 votes vote down vote up
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 
Example #2
Source File: gfxdraw_test.py    From fxxkpython with GNU General Public License v3.0 6 votes vote down vote up
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) 
Example #3
Source File: gfxdraw_test.py    From fxxkpython with GNU General Public License v3.0 6 votes vote down vote up
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) 
Example #4
Source File: gfxdraw_test.py    From fxxkpython with GNU General Public License v3.0 6 votes vote down vote up
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) 
Example #5
Source File: main.py    From python-examples with MIT License 6 votes vote down vote up
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) 
Example #6
Source File: gfxdraw_test.py    From fxxkpython with GNU General Public License v3.0 6 votes vote down vote up
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) 
Example #7
Source File: gfxdraw_test.py    From fxxkpython with GNU General Public License v3.0 6 votes vote down vote up
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) 
Example #8
Source File: aacircle.py    From fxxkpython with GNU General Public License v3.0 6 votes vote down vote up
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() 
Example #9
Source File: aacircle.py    From fxxkpython with GNU General Public License v3.0 6 votes vote down vote up
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() 
Example #10
Source File: gfxdraw_test.py    From fxxkpython with GNU General Public License v3.0 6 votes vote down vote up
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) 
Example #11
Source File: gfxdraw_test.py    From fxxkpython with GNU General Public License v3.0 6 votes vote down vote up
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) 
Example #12
Source File: gfxdraw_test.py    From fxxkpython with GNU General Public License v3.0 6 votes vote down vote up
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) 
Example #13
Source File: gfxdraw_test.py    From fxxkpython with GNU General Public License v3.0 6 votes vote down vote up
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) 
Example #14
Source File: gfxdraw_test.py    From fxxkpython with GNU General Public License v3.0 6 votes vote down vote up
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) 
Example #15
Source File: gfxdraw_test.py    From fxxkpython with GNU General Public License v3.0 6 votes vote down vote up
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) 
Example #16
Source File: gfxdraw_test.py    From fxxkpython with GNU General Public License v3.0 6 votes vote down vote up
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) 
Example #17
Source File: gfxdraw_test.py    From fxxkpython with GNU General Public License v3.0 6 votes vote down vote up
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) 
Example #18
Source File: gfxdraw_test.py    From fxxkpython with GNU General Public License v3.0 6 votes vote down vote up
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) 
Example #19
Source File: aacircle.py    From fxxkpython with GNU General Public License v3.0 6 votes vote down vote up
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() 
Example #20
Source File: gfxdraw_test.py    From fxxkpython with GNU General Public License v3.0 6 votes vote down vote up
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) 
Example #21
Source File: gfxdraw_test.py    From fxxkpython with GNU General Public License v3.0 6 votes vote down vote up
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) 
Example #22
Source File: gfxdraw_test.py    From fxxkpython with GNU General Public License v3.0 6 votes vote down vote up
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) 
Example #23
Source File: gfxdraw_test.py    From fxxkpython with GNU General Public License v3.0 6 votes vote down vote up
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) 
Example #24
Source File: aacircle.py    From fxxkpython with GNU General Public License v3.0 6 votes vote down vote up
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() 
Example #25
Source File: gfxdraw_test.py    From fxxkpython with GNU General Public License v3.0 6 votes vote down vote up
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) 
Example #26
Source File: gfxdraw_test.py    From fxxkpython with GNU General Public License v3.0 5 votes vote down vote up
def test_polygon(self):
        """polygon(surface, points, color): return None"""
        fg = self.foreground_color
        bg = self.background_color
        points = [(10, 80), (10, 15), (92, 25), (92, 80)]
        fg_test_points = (points +
                          [(points[0][0], points[0][1] - 1),
                           (points[0][0] + 1, points[0][1]),
                           (points[3][0] - 1, points[3][1]),
                           (points[3][0], points[3][1] - 1),
                           (points[2][0], points[2][1] + 1)])
        bg_test_points = [(points[0][0] - 1, points[0][1]),
                          (points[0][0], points[0][1] + 1),
                          (points[0][0] - 1, points[0][1] + 1),
                          (points[0][0] + 1, points[0][1] - 1),
                          (points[3][0] + 1, points[3][1]),
                          (points[3][0], points[3][1] + 1),
                          (points[3][0] + 1, points[3][1] + 1),
                          (points[3][0] - 1, points[3][1] - 1),
                          (points[2][0] + 1, points[2][1]),
                          (points[2][0] - 1, points[2][1] + 1),
                          (points[1][0] - 1, points[1][1]),
                          (points[1][0], points[1][1] - 1),
                          (points[1][0] - 1, points[1][1] - 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.polygon(surf, points, 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) 
Example #27
Source File: gfxdraw_test.py    From fxxkpython with GNU General Public License v3.0 5 votes vote down vote up
def test_box(self):
        """box(surface, rect, color): return None"""
        fg = self.foreground_color
        bg = self.background_color
        rect = pygame.Rect(10, 15, 55, 62)
        rect_tuple = tuple(rect)
        fg_test_points = [rect.topleft,
                          (rect.left + 1, rect.top + 1),
                          (rect.right - 1, rect.top),
                          (rect.right - 2, rect.top + 1),
                          (rect.left, rect.bottom - 1),
                          (rect.left + 1, rect.bottom - 2),
                          (rect.right - 1, rect.bottom - 1),
                          (rect.right - 2, rect.bottom - 2)]
        bg_test_points = [(rect.left - 1, rect.top - 1),
                          (rect.right, rect.top - 1),
                          (rect.left - 1, rect.bottom),
                          (rect.right, rect.bottom)]
        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.box(surf, rect, 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)
            surf.fill(bg)
            pygame.gfxdraw.box(surf, rect_tuple, 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) 
Example #28
Source File: gfxdraw_test.py    From fxxkpython with GNU General Public License v3.0 5 votes vote down vote up
def test_ellipse(self):
        """ellipse(surface, x, y, rx, ry, color): return None"""
        fg = self.foreground_color
        bg = self.background_color
        x = 45
        y = 40
        rx = 30
        ry = 35
        fg_test_points = [(x, y - ry),
                          (x, y + ry),
                          (x - rx, y),
                          (x + rx, y)]
        bg_test_points = [(x, y),
                          (x, y - ry + 1),
                          (x, y - ry - 1),
                          (x, y + ry + 1),
                          (x, y + ry - 1),
                          (x - rx - 1, y),
                          (x - rx + 1, y),
                          (x + rx + 1, y),
                          (x + rx - 1, y)]
        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.ellipse(surf, x, y, rx, ry, 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) 
Example #29
Source File: gfxdraw_test.py    From fxxkpython with GNU General Public License v3.0 5 votes vote down vote up
def test_gfxdraw__subclassed_surface(self):
        """Ensure pygame.gfxdraw works on subclassed surfaces."""
        surface = SurfaceSubclass((11, 13), SRCALPHA, 32)
        surface.fill(pygame.Color('blue'))
        expected_color = pygame.Color('red')
        x, y = 1, 2

        pygame.gfxdraw.pixel(surface, x, y, expected_color)

        self.assertEqual(surface.get_at((x, y)), expected_color) 
Example #30
Source File: gfxdraw_test.py    From fxxkpython with GNU General Public License v3.0 5 votes vote down vote up
def test_filled_polygon(self):
        """filled_polygon(surface, points, color): return None"""
        fg = self.foreground_color
        bg = self.background_color
        points = [(10, 80), (10, 15), (92, 25), (92, 80)]
        fg_test_points = (points +
                          [(points[0][0], points[0][1] - 1),
                           (points[0][0] + 1, points[0][1]),
                           (points[0][0] + 1, points[0][1] - 1),
                           (points[3][0] - 1, points[3][1]),
                           (points[3][0], points[3][1] - 1),
                           (points[3][0] - 1, points[3][1] - 1),
                           (points[2][0], points[2][1] + 1),
                           (points[2][0] - 1, points[2][1] + 1)])
        bg_test_points = [(points[0][0] - 1, points[0][1]),
                          (points[0][0], points[0][1] + 1),
                          (points[0][0] - 1, points[0][1] + 1),
                          (points[3][0] + 1, points[3][1]),
                          (points[3][0], points[3][1] + 1),
                          (points[3][0] + 1, points[3][1] + 1),
                          (points[2][0] + 1, points[2][1]),
                          (points[1][0] - 1, points[1][1]),
                          (points[1][0], points[1][1] - 1),
                          (points[1][0] - 1, points[1][1] - 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_polygon(surf, points, 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)