【发布时间】:2014-06-25 14:28:09
【问题描述】:
我最近发现了可以在 pygame 中应用于 blitted 表面的不同混合模式,我想看看这个系统有多灵活。除非我做错了什么,否则它显然非常有限(就像 pygame OOOOOOOH 射击的其余部分一样)。我写了一个简单的程序,它使用 alpha 绘制一堆渐变圆,然后在屏幕上到处显示。这是代码:
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 可以正确计算为浮点数。
【问题讨论】:
-
@user667648 您发布的答案就是我一直在寻找的答案!把它放回去,这样我就可以接受了! :)
-
好的!我只是在考虑较低的 alpha 水平,这似乎有点可疑……
标签: python python-3.x pygame