Python pygame 模块,gfxdraw() 实例源码

我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用pygame.gfxdraw()

项目:Projects    作者:it2school    | 项目源码 | 文件源码
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()
项目:Projects    作者:it2school    | 项目源码 | 文件源码
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)
项目:Projects    作者:it2school    | 项目源码 | 文件源码
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)
项目:Projects    作者:it2school    | 项目源码 | 文件源码
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)
项目:Projects    作者:it2school    | 项目源码 | 文件源码
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)
项目:Projects    作者:it2school    | 项目源码 | 文件源码
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)
项目:Projects    作者:it2school    | 项目源码 | 文件源码
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)
项目:MVP2    作者:critterandguitari    | 项目源码 | 文件源码
def draw(screen, mvp):
    if mvp.quarter_note :
        #color = (random.randrange(0,255), random.randrange(0,255), random.randrange(0,255))
        color = (random.randrange(0,25), random.randrange(0,25), random.randrange(0,25))
        screen.fill(color) 


    if True:#mvp.note_on :
        x=random.randrange(0,1920)  + mvp.knob2 // 2
        y=random.randrange(0,1080)  + mvp.knob3 // 2
        size = mvp.knob1 // 20 + 20
        color = (random.randrange(0,255), random.randrange(0,255), random.randrange(0, 255))
        #color = pygame.Color.hsva( (float(mvp.knob3) / 1024) * 360, 100, 100, 50)#(random.randrange(0,255), random.randrange(0,255), random.randrange(0,255))
        #color = Color.hsva( 20, 100, 100, 50)#(random.randrange(0,255), random.randrange(0,255), random.randrange(0,255))
        width = mvp.knob1 // 50
        if width == 0 : width = 1
        if width > size : width = size
        pos = (x,y)#pygame.mouse.get_pos()
        pygame.draw.circle(screen,color,pos,size, 0)
        pygame.gfxdraw.aacircle(screen, x, y, size, color)
        #pygame.gfxdraw.filled_circle(screen, x, y, size, color)
项目:MVP2    作者:critterandguitari    | 项目源码 | 文件源码
def draw(screen, mvp):
    global count, rany, ranx

    if True: #mvp.note_on :

        count += 1  
        if count > mvp.knob3 // 20:
            count = 0
            #screen.fill((0,0,0))
            rany = random.randrange(0,screen.get_height())#random.randomrange(0, screen.get_height())
            ranx = random.randrange(0,screen.get_width())#random.randomrange(0, screen.get_width())

        x=ranx + count * 4
        y=rany + count * 4
        size = 20 + count
        color = (random.randrange(0,250), random.randrange(0,250), random.randrange(0,255))

        pos = (x,y)#pygame.mouse.get_pos()
        pygame.draw.circle(screen,color,pos,size, 0)
        time.sleep(.05)
#        pygame.gfxdraw.aacircle(screen, x, y, size, color)
#        pygame.gfxdraw.filled_circle(screen, x, y, size, color)
项目:MVP2    作者:critterandguitari    | 项目源码 | 文件源码
def draw(screen, mvp):

    global count
    if True: #mvp.note_on:


        #if count > mvp.knob3 //
        x=random.randrange(0,1300)
        y=random.randrange(0,800)
        pierad=random.randrange(10,100) #radius
        arcstart=random.randrange(0,360)
        arcend=random.randrange(0, 360-arcstart)
        size = int(mvp.knob2 * 1000)
        color = mvp.color_picker()


        fillrange=int(mvp.knob1*100)
        for i in range(fillrange):
            pygame.gfxdraw.pie(screen, x, y, size, arcstart + i*2, arcend - i*2, color)
项目:MVP2    作者:critterandguitari    | 项目源码 | 文件源码
def draw(screen, mvp):

    global count
    if True: #mvp.note_on:

        #count += 1  
        #if count > mvp.knob3:
        #    count = 0
        #    screen.fill((0,0,0))

        #if count > mvp.knob3 //
        x=random.randrange(0,1300)
        y=random.randrange(0,800)
        pierad=random.randrange(10,100) #radius
        arcstart=random.randrange(0,360)
        arcend=random.randrange(0, 360-arcstart)
        size = int(mvp.knob2*1000)

        color = pygame.Color(random.randrange(0,255), random.randrange(0,255), random.randrange(0,255), 10)
        color.hsva = (int(mvp.knob4 * 359), 100, 100, 10)


        fillrange=int(mvp.knob1*100)
        for i in range(fillrange):
            pygame.gfxdraw.pie(screen, x, y, size, arcstart + i*2, arcend - i*2, color)
项目:AIFun    作者:Plottel    | 项目源码 | 文件源码
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.gfxdraw.aacircle(s, 250, 250, 200, (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()
项目:AIFun    作者:Plottel    | 项目源码 | 文件源码
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)
项目:AIFun    作者:Plottel    | 项目源码 | 文件源码
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)
项目:AIFun    作者:Plottel    | 项目源码 | 文件源码
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)
项目:AIFun    作者:Plottel    | 项目源码 | 文件源码
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)
项目:AIFun    作者:Plottel    | 项目源码 | 文件源码
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)
项目:AIFun    作者:Plottel    | 项目源码 | 文件源码
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)
项目:panotti    作者:drscotthawley    | 项目源码 | 文件源码
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
项目:ETC_Modes    作者:critterandguitari    | 项目源码 | 文件源码
def draw(screen, etc) :
    color = etc.color_picker() #on knob4

    triangles = int(etc.knob1*70)+1
    space = (1280/triangles)
    offset = int(etc.knob2*space)-(space/2)
    y = int(etc.knob3*720)


    for i in range (0,triangles+1) :


        auDio = int(etc.audio_in[i] / 65)

        ax = i * space

        pygame.gfxdraw.filled_trigon(screen, ax, y, ax+int((space/2)+offset),auDio+y, ax + space, y, color)
项目:ETC_Modes    作者:critterandguitari    | 项目源码 | 文件源码
def seg(screen, etc, i) :
    global lx, ly
    x0 = 960#random.randrange(0,1920)
    x1 = 960 + (etc.audio_in[i] / 35)#random.randrange(0,1920)
   # y = i * 10#random.randrange(0,1080)
    #color = (random.randrange(0,255), random.randrange(0,255), random.randrange(0,255))
    color = etc.color_picker()
    R = int(etc.knob1 * 1000)
    R = R + (etc.audio_in[i] / 100)
    x = R * math.cos((i /  100.) * 6.28) + 640
    y = R * math.sin((i /  100.) * 6.28) + 260

    #pygame.draw.line(screen, color, [lx, ly], [x, y], 1)
    #pygame.draw.circle(screen,color,[int(x), int(y)], etc.knob1 / 50, 0)
    if ((i % 2)) :
        pygame.gfxdraw.filled_trigon(screen, int(x), int(y), int(x) + int(etc.knob2*200) + random.randrange(0,78), int(y) + int(etc.knob2*200), int(x) - int(etc.knob3*200), int(y) + int(etc.knob3*200), color)
    else :
        color = (random.randrange(0,255), random.randrange(0,255), random.randrange(0,255))
        pygame.gfxdraw.trigon(screen, int(x), int(y), int(x) + int(etc.knob2*200) + random.randrange(0,78), int(y) + int(etc.knob2*200), int(x) - int(etc.knob3*200), int(y) + int(etc.knob3*200), color)


    #pygame.draw.line(screen, color, [x0 , y ], [x1 , y+10], 10)
项目:ETC_Modes    作者:critterandguitari    | 项目源码 | 文件源码
def draw(screen, etc):
    global count, size

    if etc.audio_trig or etc.midi_note_new :

        x=random.randrange(0,1300)
        y=random.randrange(0,800)
        pierad=random.randrange(10,100) 
        arcstart=random.randrange(0,360)
        arcend=random.randrange(0, 360-arcstart)

        fillrange = int(etc.knob2*100)+ 1
        diameter = int(etc.knob1 * 1000)+1
        nest = int(etc.knob3 * 10)
        color = etc.color_picker()



        for i in range(fillrange):
            size = diameter-(nest*i)
            if size < 0 : size = 5
            pygame.gfxdraw.pie(screen, x, y, size, arcstart + i*2, arcend - i*2, color)
项目:Projects    作者:it2school    | 项目源码 | 文件源码
def test_pixel(self):
        """pixel(surface, x, y, color): return None"""
        fg = self.foreground_color
        bg = self.background_color
        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.pixel(surf, 2, 2, fg)
            for x in range(1, 4):
                for y in range(1, 4):
                    if x == 2 and y == 2:
                        self.check_at(surf, (x, y), fg_adjusted)
                    else:
                        self.check_at(surf, (x, y), bg_adjusted)
项目:Projects    作者:it2school    | 项目源码 | 文件源码
def test_rectangle(self):
        """rectangle(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.right - 1, rect.top),
                          (rect.left, rect.bottom - 1),
                          (rect.right - 1, rect.bottom - 1)]
        bg_test_points = [(rect.left - 1, rect.top - 1),
                          (rect.left + 1, rect.top + 1),
                          (rect.right, rect.top - 1),
                          (rect.right - 2, rect.top + 1),
                          (rect.left - 1, rect.bottom),
                          (rect.left + 1, rect.bottom - 2),
                          (rect.right, rect.bottom),
                          (rect.right - 2, rect.bottom - 2)]
        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.rectangle(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.rectangle(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)
项目:Projects    作者:it2school    | 项目源码 | 文件源码
def test_circle(self):
        """circle(surface, x, y, r, color): return None"""
        fg = self.foreground_color
        bg = self.background_color
        x = 45
        y = 40
        r = 30
        fg_test_points = [(x, y - r),
                          (x, y + r),
                          (x - r, y),
                          (x + r, y)]
        bg_test_points = [(x, y),
                          (x, y - r + 1),
                          (x, y - r - 1),
                          (x, y + r + 1),
                          (x, y + r - 1),
                          (x - r - 1, y),
                          (x - r + 1, y),
                          (x + r + 1, y),
                          (x + r - 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.circle(surf, x, y, r, 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)
项目:Projects    作者:it2school    | 项目源码 | 文件源码
def test_arc(self):
        """arc(surface, x, y, r, start, end, color): return None"""
        fg = self.foreground_color
        bg = self.background_color
        x = 45
        y = 40
        r = 30
        start = 0  # +x direction, but not (x + r, y) (?)
        end = 90   # -y direction, including (x, y + r)
        fg_test_points = [(x, y + r), (x + r, y + 1)]
        bg_test_points = [(x, y),
                          (x, y - r),
                          (x - r, y),
                          (x, y + r + 1),
                          (x, y + r - 1),
                          (x - 1, y + r),
                          (x + r + 1, y),
                          (x + r - 1, y),
                          (x + r, 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.arc(surf, x, y, r, start, end, 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)
项目:Projects    作者:it2school    | 项目源码 | 文件源码
def test_aacircle(self):
        """aacircle(surface, x, y, r, color): return None"""
        fg = self.foreground_color
        bg = self.background_color
        x = 45
        y = 40
        r = 30
        fg_test_points = [(x, y - r),
                          (x, y + r),
                          (x - r, y),
                          (x + r, y)]
        bg_test_points = [(x, y),
                          (x, y - r + 1),
                          (x, y - r - 1),
                          (x, y + r + 1),
                          (x, y + r - 1),
                          (x - r - 1, y),
                          (x - r + 1, y),
                          (x + r + 1, y),
                          (x + r - 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.aacircle(surf, x, y, r, 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)
项目:Projects    作者:it2school    | 项目源码 | 文件源码
def test_filled_circle(self):
        """filled_circle(surface, x, y, r, color): return None"""
        fg = self.foreground_color
        bg = self.background_color
        x = 45
        y = 40
        r = 30
        fg_test_points = [(x, y - r),
                          (x, y - r + 1),
                          (x, y + r),
                          (x, y + r - 1),
                          (x - r, y),
                          (x - r + 1, y),
                          (x + r, y),
                          (x + r - 1, y),
                          (x, y)]
        bg_test_points = [(x, y - r - 1),
                          (x, y + r + 1),
                          (x - r - 1, y),
                          (x + r + 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.filled_circle(surf, x, y, r, 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)
项目:Projects    作者:it2school    | 项目源码 | 文件源码
def test_aaellipse(self):
        """aaellipse(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.aaellipse(surf, x, y, rx, ry, 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)
项目:Projects    作者:it2school    | 项目源码 | 文件源码
def test_filled_ellipse(self):
        """filled_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 + 1),
                          (x, y + ry),
                          (x, y + ry - 1),
                          (x - rx, y),
                          (x - rx + 1, y),
                          (x + rx, y),
                          (x + rx - 1, y),
                          (x, y)]
        bg_test_points = [(x, y - ry - 1),
                          (x, y + ry + 1),
                          (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.filled_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)
项目:Projects    作者:it2school    | 项目源码 | 文件源码
def test_pie(self):
        """pie(surface, x, y, r, start, end, color): return None"""
        fg = self.foreground_color
        bg = self.background_color
        x = 45
        y = 40
        r = 30
        start = 0  # +x direction, including (x + r, y)
        end = 90   # -y direction, but not (x, y + r) (?)
        fg_test_points = [(x, y),
                          (x + 1, y),
                          (x, y + 1),
                          (x + r, y)]
        bg_test_points = [(x - 1, y),
                          (x, y - 1),
                          (x - 1, y - 1),
                          (x + 1, y + 1),
                          (x + r + 1, y),
                          (x + r, y - 1),
                          (x, y + r)]
        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.pie(surf, x, y, r, start, end, 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)
项目:Projects    作者:it2school    | 项目源码 | 文件源码
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)
项目:Projects    作者:it2school    | 项目源码 | 文件源码
def test_aapolygon(self):
        """aapolygon(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.aapolygon(surf, points, 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)
项目:Projects    作者:it2school    | 项目源码 | 文件源码
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)
项目:Projects    作者:it2school    | 项目源码 | 文件源码
def test_textured_polygon(self):
        """textured_polygon(surface, points, texture, tx, ty): return None"""
        w, h = self.default_size
        fg = self.foreground_color
        bg = self.background_color
        tx = 0
        ty = 0
        texture = pygame.Surface((w + tx, h + ty), 0, 24)
        texture.fill(fg, (0, 0, w, h))
        points = [(10, 80), (10, 15), (92, 25), (92, 80)]
        # Don't know how to really check this as boarder points may
        # or may not be included in the textured polygon.
        fg_test_points = [(points[1][0] + 30, points[1][1] + 40)]
        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[1:]:
            fg_adjusted = surf.unmap_rgb(surf.map_rgb(fg))
            bg_adjusted = surf.unmap_rgb(surf.map_rgb(bg))
            pygame.gfxdraw.textured_polygon(surf, points, texture, -tx, -ty)
            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)

        # Alpha blit to 8 bits-per-pixel surface forbidden.
        texture = pygame.Surface(self.default_size, SRCALPHA, 32)
        self.failUnlessRaises(ValueError,
                              pygame.gfxdraw.textured_polygon,
                              self.surfaces[0],
                              points,
                              texture, 0, 0)
项目:LD35    作者:raffitz    | 项目源码 | 文件源码
def renderstar(targetsurface,star):
    pygame.gfxdraw.pixel(targetsurface,int(star[0] + gamewidth//2 - px),int(star[1] + gameheight//2 + py),(star[2],star[2],star[2]))
项目:AlphaBubble    作者:laurenssam    | 项目源码 | 文件源码
def draw(self):
            pygame.gfxdraw.filled_circle(DISPLAYSURF, self.rect.centerx, self.rect.centery, self.radius, self.color)
            pygame.gfxdraw.aacircle(DISPLAYSURF, self.rect.centerx, self.rect.centery, self.radius, GRAY)
项目:MVP2    作者:critterandguitari    | 项目源码 | 文件源码
def draw(screen, mvp):
    global count
    #if mvp.half_note: 
    #    screen.fill((0,0,0))

    if True:
        count += 1  
        if count > mvp.knob4:
            count = 0
            screen.fill((0,0,0))

        x=random.randrange(0,700)
        y=random.randrange(0,400)
        pierad=random.randrange(10,) #radius
        arcstart=random.randrange(0,360)
        arcend=random.randrange(0, 360-arcstart)
        coloralpha=mvp.knob3/4
#        size = mvp.knob2
        color = (random.randrange(0,255), random.randrange(0,255), random.randrange(0,255), coloralpha)
#        width = mvp.knob1 // 50
#        if width == 0 : width = 1
#        if width > size : width = size 
        nestrange=mvp.knob1/8
        fanrange=mvp.knob2/10
        count=0
        for i in range(nestrange):
            count = i
            arcstart=random.randrange(0,360)
            arcend=random.randrange(0, 360-arcstart)
            for i in range(fanrange):
                pygame.gfxdraw.pie(screen, screen.get_width()/2, screen.get_height()/2, screen.get_height() - (count*screen.get_height()/nestrange), arcstart + i*fanrange, arcend - i*fanrange, color)

                #pygame.gfxdraw.pie(screen, screen.get_width()/2, screen.get_height()/2, (nestrange-count)*, arcstart + i*fanrange, arcend - i*fanrange, color)
#            time.sleep(.05)
            pygame.display.flip() #updates the display surface
        #screen.fill((0,0,0))
#        pygame.gfxdraw.pie(screen, x, y, pierad, 5, 50, color)
#        pygame.draw.circle(screen,color,[x,y],size, 0)
#        pygame.gfxdraw.aacircle(screen, x, y, size, color)

#pgyame.gfxdraw.pie(surface, x, y, radius, arcstart, arcend, color): return None
项目:MVP2    作者:critterandguitari    | 项目源码 | 文件源码
def draw(screen, mvp):

    if mvp.note_on:
        x=random.randrange(0,700)
        y=random.randrange(0,400)
        pierad=random.randrange(10,) #radius
        arcstart=random.randrange(0,360)
        arcend=random.randrange(0, 360-arcstart)
        coloralpha=mvp.knob3/4
#       size = mvp.knob2
        color = (random.randrange(0,255), random.randrange(0,255), random.randrange(0,255), coloralpha)
#       width = mvp.knob1 // 50
#       if width == 0 : width = 1
#       if width > size : width = size 
        nestrange=mvp.knob1/8
        fanrange=mvp.knob2/10
        count=0
        for i in range(nestrange):
            count = i
            arcstart=random.randrange(0,360)
            arcend=random.randrange(0, 360-arcstart)
            for i in range(fanrange):
                pygame.gfxdraw.pie(screen, screen.get_width()/2, screen.get_height(), screen.get_height() - (count*screen.get_height()/nestrange), arcstart + i*fanrange, arcend - i*fanrange, color)
                #pygame.gfxdraw.pie(screen, screen.get_width()/2, screen.get_height()/2, (nestrange-count)*, arcstart + i*fanrange, arcend - i*fanrange, color)
            pygame.display.flip() #updates the display surface





#pgyame.gfxdraw.pie(surface, x, y, radius, arcstart, arcend, color): return None
项目:MVP2    作者:critterandguitari    | 项目源码 | 文件源码
def draw(screen, mvp):

    global count
    if mvp.note_on:

        count += 1  
        if count > mvp.knob3:
            count = 0
            screen.fill((0,0,0))

        #if count > mvp.knob3 //
        x=random.randrange(0,700)
        y=random.randrange(0,400)
        pierad=random.randrange(10,100) #radius
        arcstart=random.randrange(0,360)
        arcend=random.randrange(0, 360-arcstart)
        size = mvp.knob2
        #color = (random.randrange(254,255), random.randrange(100,255), random.randrange(0,255))

        #color = pygame.Color(random.randrange(0,255), random.randrange(0,255), random.randrange(0,255), (float(mvp.knob4) / 1024) * 100)
        coloralpha=mvp.knob4/4
#        size = mvp.knob2
        color = (random.randrange(0,255), random.randrange(0,255), random.randrange(0,255), coloralpha)
        #color.hsva = ((float(mvp.knob4) / 1024) * 360, 100, 100, (float(mvp.knob4) / 1024) * 100)


        fillrange=mvp.knob1/10
        for i in range(fillrange):
            pygame.gfxdraw.pie(screen, x, y, size, arcstart + i*2, arcend - i*2, color)

#       pygame.gfxdraw.pie(screen, x, y, pierad, 5, 50, color)
#        pygame.draw.circle(screen,color,[x,y],size, 0)
#        pygame.gfxdraw.aacircle(screen, x, y, size, color)
#        pygame.gfxdraw.filled_circle(screen, x, y, size, color)

#pgyame.gfxdraw.pie(surface, x, y, radius, arcstart, arcend, color): return None
项目:MVP2    作者:critterandguitari    | 项目源码 | 文件源码
def draw(screen, mvp):

    global count
    if mvp.note_on:

        count += 1  
        if count > mvp.knob3:
            count = 0
            screen.fill((0,0,0))

        #if count > mvp.knob3 //
        x=random.randrange(0,700)
        y=random.randrange(0,400)
        pierad=random.randrange(10,100) #radius
        arcstart=random.randrange(0,360)
        arcend=random.randrange(0, 360-arcstart)
        size = mvp.knob2
        #color = (random.randrange(254,255), random.randrange(100,255), random.randrange(0,255))

        color = pygame.Color(random.randrange(0,255), random.randrange(0,255), random.randrange(0,255), 10)
#        size = mvp.knob2
        color.hsva = ((float(mvp.knob4) / 1024) * 360, 100, 100, 10)


        fillrange=mvp.knob1/10
        for i in range(fillrange):
            pygame.gfxdraw.pie(screen, x, y, size, arcstart + i*2, arcend - i*2, color)

#       pygame.gfxdraw.pie(screen, x, y, pierad, 5, 50, color)
#        pygame.draw.circle(screen,color,[x,y],size, 0)
#        pygame.gfxdraw.aacircle(screen, x, y, size, color)
#        pygame.gfxdraw.filled_circle(screen, x, y, size, color)

#pgyame.gfxdraw.pie(surface, x, y, radius, arcstart, arcend, color): return None
项目:MVP2    作者:critterandguitari    | 项目源码 | 文件源码
def draw(screen, mvp):
    global count
    #if mvp.half_note: 
    #    screen.fill((0,0,0))

    if True:
        count += 1  
        if count > mvp.knob4:
            count = 0
            screen.fill((0,0,0))

        x=random.randrange(0,700)
        y=random.randrange(0,400)
        pierad=random.randrange(10,) #radius
        arcstart=random.randrange(0,360)
        arcend=random.randrange(0, 360-arcstart)
        coloralpha=mvp.knob3/4
#        size = mvp.knob2
        color = (random.randrange(0,255), random.randrange(0,255), random.randrange(0,255), coloralpha)
#        width = mvp.knob1 // 50
#        if width == 0 : width = 1
#        if width > size : width = size 
        nestrange=mvp.knob1/8
        fanrange=mvp.knob2/10
        count=0
        for i in range(nestrange):
            count = i
            arcstart=random.randrange(0,360)
            arcend=random.randrange(0, 360-arcstart)
            for i in range(fanrange):
                pygame.gfxdraw.pie(screen, screen.get_width()/2, screen.get_height()/2, screen.get_height() - (count*screen.get_height()/nestrange), arcstart + i*fanrange, arcend - i*fanrange, color)

                #pygame.gfxdraw.pie(screen, screen.get_width()/2, screen.get_height()/2, (nestrange-count)*, arcstart + i*fanrange, arcend - i*fanrange, color)
#            time.sleep(.05)
            pygame.display.flip() #updates the display surface
        #screen.fill((0,0,0))
#        pygame.gfxdraw.pie(screen, x, y, pierad, 5, 50, color)
#        pygame.draw.circle(screen,color,[x,y],size, 0)
#        pygame.gfxdraw.aacircle(screen, x, y, size, color)

#pgyame.gfxdraw.pie(surface, x, y, radius, arcstart, arcend, color): return None
项目:MVP2    作者:critterandguitari    | 项目源码 | 文件源码
def draw(screen, mvp):

    global count
    if True:

        count += 1  
        if count > mvp.knob3:
            count = 0
            screen.fill((0,0,0))

        #if count > mvp.knob3 //
        x=random.randrange(0,700)
        y=random.randrange(0,400)
        pierad=random.randrange(10,100) #radius
        arcstart=random.randrange(0,360)
        arcend=random.randrange(0, 360-arcstart)
        size = mvp.knob2
        color = (random.randrange(0,255), random.randrange(0,255), random.randrange(0,255))


        fillrange=mvp.knob1/10
        for i in range(fillrange):
            pygame.gfxdraw.pie(screen, x, y, size, arcstart + i*2, arcend - i*2, color)

#       pygame.gfxdraw.pie(screen, x, y, pierad, 5, 50, color)
#        pygame.draw.circle(screen,color,[x,y],size, 0)
#        pygame.gfxdraw.aacircle(screen, x, y, size, color)
#        pygame.gfxdraw.filled_circle(screen, x, y, size, color)

#pgyame.gfxdraw.pie(surface, x, y, radius, arcstart, arcend, color): return None
项目:MVP2    作者:critterandguitari    | 项目源码 | 文件源码
def square(screen):
    x = random.randrange(0,screen.get_width())
    y = random.randrange(0,screen.get_height())
    color = (random.randrange(0,255), random.randrange(0,255), random.randrange(0,255))
    #pygame.draw.line(screen, color, [x, y], [x,y+100 ], 100)
    #pygame.draw.rect(screen, color, [x, y, x+100,y+100 ], 10)
    pygame.gfxdraw.box(screen, [x, y, x+100,y+100 ], color)
项目:AIFun    作者:Plottel    | 项目源码 | 文件源码
def test_pixel(self):
        """pixel(surface, x, y, color): return None"""
        fg = self.foreground_color
        bg = self.background_color
        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.pixel(surf, 2, 2, fg)
            for x in range(1, 4):
                for y in range(1, 4):
                    if x == 2 and y == 2:
                        self.check_at(surf, (x, y), fg_adjusted)
                    else:
                        self.check_at(surf, (x, y), bg_adjusted)
项目:AIFun    作者:Plottel    | 项目源码 | 文件源码
def test_rectangle(self):
        """rectangle(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.right - 1, rect.top),
                          (rect.left, rect.bottom - 1),
                          (rect.right - 1, rect.bottom - 1)]
        bg_test_points = [(rect.left - 1, rect.top - 1),
                          (rect.left + 1, rect.top + 1),
                          (rect.right, rect.top - 1),
                          (rect.right - 2, rect.top + 1),
                          (rect.left - 1, rect.bottom),
                          (rect.left + 1, rect.bottom - 2),
                          (rect.right, rect.bottom),
                          (rect.right - 2, rect.bottom - 2)]
        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.rectangle(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.rectangle(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)
项目:AIFun    作者:Plottel    | 项目源码 | 文件源码
def test_circle(self):
        """circle(surface, x, y, r, color): return None"""
        fg = self.foreground_color
        bg = self.background_color
        x = 45
        y = 40
        r = 30
        fg_test_points = [(x, y - r),
                          (x, y + r),
                          (x - r, y),
                          (x + r, y)]
        bg_test_points = [(x, y),
                          (x, y - r + 1),
                          (x, y - r - 1),
                          (x, y + r + 1),
                          (x, y + r - 1),
                          (x - r - 1, y),
                          (x - r + 1, y),
                          (x + r + 1, y),
                          (x + r - 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.circle(surf, x, y, r, 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)
项目:AIFun    作者:Plottel    | 项目源码 | 文件源码
def test_arc(self):
        """arc(surface, x, y, r, start, end, color): return None"""
        fg = self.foreground_color
        bg = self.background_color
        x = 45
        y = 40
        r = 30
        start = 0  # +x direction, but not (x + r, y) (?)
        end = 90   # -y direction, including (x, y + r)
        fg_test_points = [(x, y + r), (x + r, y + 1)]
        bg_test_points = [(x, y),
                          (x, y - r),
                          (x - r, y),
                          (x, y + r + 1),
                          (x, y + r - 1),
                          (x - 1, y + r),
                          (x + r + 1, y),
                          (x + r - 1, y),
                          (x + r, 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.arc(surf, x, y, r, start, end, 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)
项目:AIFun    作者:Plottel    | 项目源码 | 文件源码
def test_aacircle(self):
        """aacircle(surface, x, y, r, color): return None"""
        fg = self.foreground_color
        bg = self.background_color
        x = 45
        y = 40
        r = 30
        fg_test_points = [(x, y - r),
                          (x, y + r),
                          (x - r, y),
                          (x + r, y)]
        bg_test_points = [(x, y),
                          (x, y - r + 1),
                          (x, y - r - 1),
                          (x, y + r + 1),
                          (x, y + r - 1),
                          (x - r - 1, y),
                          (x - r + 1, y),
                          (x + r + 1, y),
                          (x + r - 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.aacircle(surf, x, y, r, 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)
项目:AIFun    作者:Plottel    | 项目源码 | 文件源码
def test_filled_circle(self):
        """filled_circle(surface, x, y, r, color): return None"""
        fg = self.foreground_color
        bg = self.background_color
        x = 45
        y = 40
        r = 30
        fg_test_points = [(x, y - r),
                          (x, y - r + 1),
                          (x, y + r),
                          (x, y + r - 1),
                          (x - r, y),
                          (x - r + 1, y),
                          (x + r, y),
                          (x + r - 1, y),
                          (x, y)]
        bg_test_points = [(x, y - r - 1),
                          (x, y + r + 1),
                          (x - r - 1, y),
                          (x + r + 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.filled_circle(surf, x, y, r, 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)