【问题标题】:Additive blending in pygame doesn't work with alphapygame 中的加法混合不适用于 alpha
【发布时间】: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


【解决方案1】:

问题仍然在于这一行:

colour += (int(15/255*100), )

它最初应该是白色的,但是 alpha 太低了,需要很长时间(嗯,理论上应该......)。

在做:

colour += (int(125/255*100), )

让效果更明显。

结果:

【讨论】:

  • 不不,我使用的是 python 3,抱歉我应该说清楚。您发布的结果就是我现在得到的结果,我想要的是添加剂混合最终将绿色混合为白色,因为越来越多的圆圈重叠。
  • @user3002473:这个帮助?
猜你喜欢
  • 1970-01-01
  • 2014-10-27
  • 1970-01-01
  • 1970-01-01
  • 2018-12-24
  • 1970-01-01
  • 2022-06-20
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多