Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/290.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何将绘制的圆与pygame混合_Python_Pygame - Fatal编程技术网

Python 如何将绘制的圆与pygame混合

Python 如何将绘制的圆与pygame混合,python,pygame,Python,Pygame,我正在尝试创建一个类似于此处的应用程序: 基本上有很多用pygame绘制的重叠圆。我不知道如何混合圆,使他们半透明。那就是让重叠的颜色显示出来。到目前为止,我的代码是: import sys, random, time import pygame from pygame.locals import * from pygame import draw rand = random.randint pygame.init( ) W = 320 H = 320 size = (W, H) sc

我正在尝试创建一个类似于此处的应用程序:

基本上有很多用pygame绘制的重叠圆。我不知道如何混合圆,使他们半透明。那就是让重叠的颜色显示出来。到目前为止,我的代码是:

import sys, random, time
import pygame
from pygame.locals import *
from pygame import draw

rand = random.randint

pygame.init( )

W = 320
H = 320
size = (W, H)

screen = pygame.display.set_mode(size)

run = True
while 1:

    for event in pygame.event.get():
        if event.type == pygame.KEYDOWN: 
            if event.key == pygame.K_SPACE :
                run = not run
            else:
                sys.exit()
    if run:
        xc = rand(1, W)
        yc = rand(1, H)
        rc = rand(1, 25)

        red = rand(1, 255)
        grn = rand(1, 255)
        blu = rand(1, 255)

        draw.circle(screen, (red, grn, blu, 200), (xc, yc), rc, 0)

        pygame.display.flip()

我把它画到了一个不是显示器的表面,并结合了SETCOLORKEY和SETALPHA函数

import pygame
from pygame.locals import *

TRANSPARENT = (255,0,255)
pygame.init()
screen = pygame.display.set_mode((500,500))

surf1 = pygame.Surface((200,200))
surf1.fill(TRANSPARENT)
surf1.set_colorkey(TRANSPARENT)
pygame.draw.circle(surf1, (0,0,200,100),(100,100), 100)

surf2 = pygame.Surface((200,200))
surf2.fill(TRANSPARENT)
surf2.set_colorkey(TRANSPARENT)
pygame.draw.circle(surf2, (200,0,0,100),(100,100), 100)

surf1.set_alpha(100)
surf2.set_alpha(100)

while True:
    screen.fill((255,255,255))

    for event in pygame.event.get():
            if event.type == QUIT:
            pygame.quit()

    screen.blit(surf1, (100,100,100,100))
    screen.blit(surf2, (200,200,100,100))
    pygame.display.flip()
附言 还可以在blit()参数中添加混合标志:
我是戴夫。在eigenfaces.com上创建这些图片。祝你的实验好运。我把代码贴在这里:

如果有用的话,请告诉我

顺便说一下。。我也尝试过电影。。。下面是大约20帧,每个帧大约有1000代: