当前位置:  开发笔记 > 编程语言 > 正文

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

如何解决《如何将绘制的圆圈与pygame混合》经验,为你挑选了1个好方法。

我正在尝试创建一个像这样的应用程序:

http://www.eigenfaces.com/

基本上用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()

Zoomulator.. 6

我通过绘制到不是显示的表面并组合设置的颜色键和设置alpha函数来使其工作.

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()

PS还有可以放在blit()参数中的混合标志: Pygame.org - Surface.blit



1> Zoomulator..:

我通过绘制到不是显示的表面并组合设置的颜色键和设置alpha函数来使其工作.

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()

PS还有可以放在blit()参数中的混合标志: Pygame.org - Surface.blit

推荐阅读
kikokikolove
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有