Python pygame中的添加剂混合不';我不能和阿尔法一起工作
我最近在pygame中发现了可以应用于blitted曲面的不同混合模式,我想看看这个系统有多灵活。除非我做错了什么,否则它显然是非常有限的(就像其他的pygame射击一样)。我写了一个简单的程序,用alpha绘制了一组渐变圆,并在屏幕上显示它们。代码如下:Python pygame中的添加剂混合不';我不能和阿尔法一起工作,python,python-3.x,pygame,Python,Python 3.x,Pygame,我最近在pygame中发现了可以应用于blitted曲面的不同混合模式,我想看看这个系统有多灵活。除非我做错了什么,否则它显然是非常有限的(就像其他的pygame射击一样)。我写了一个简单的程序,用alpha绘制了一组渐变圆,并在屏幕上显示它们。代码如下: import pygame import pygame.gfxdraw pygame.init() import random SCREEN = pygame.display.set_mode((800, 600)) SCREEN.fil
import pygame
import pygame.gfxdraw
pygame.init()
import random
SCREEN = pygame.display.set_mode((800, 600))
SCREEN.fill((0, 0, 0))
def draw_square(surface, colour, x, y):
"""
Yeah it's called draw square but it actually draws a circle thing I was just too lazy
to change the name so you gotta deal with it.
"""
square = pygame.Surface((100, 100))
square.fill((0, 0, 0))
colour += (int(15/255*100), )
for i in range(25):
pygame.gfxdraw.filled_circle(square, 50, 50, i*2, colour)
# Comment the previous two lines out and uncomment the next line to see different results.
# pygame.draw.circle(square, colour[:3], (50, 50), 50)
surface.blit(square, (x - 50, y - 50), special_flags=pygame.BLEND_RGB_ADD)
running = True
while running:
for evt in pygame.event.get():
if evt.type == pygame.QUIT:
running = False
draw_square(SCREEN, (25, 255, 25), random.randint(0, 800), random.randint(0, 600))
pygame.display.update()
pygame.quit()
它在绘制普通圆时似乎有效,但在使用pygame.gfxdraw.filled_circle
添加混合绘制圆时无效。有什么想法吗
编辑:我使用的是Python 3,因此15/255正确地计算为浮点。问题仍然在于这一行:
colour += (int(15/255*100), )
一开始它应该变成白色,但是alpha太低了,需要很长时间(理论上应该是…)
做:
colour += (int(125/255*100), )
使效果更加明显
结果:
不,不,我使用的是python 3,对不起,我应该说清楚。您发布的结果就是我现在得到的结果,我想要的是随着越来越多的圆圈重叠,添加剂混合最终将绿色混合为白色。@user3002473:这有帮助吗?@user667648您发布的答案就是我想要的答案!把它放回去,这样我就可以接受了!:)好啊我只是在想较低的阿尔法水平,它花了这么长时间似乎有点可疑。。。