What do the blend modes in pygame mean?

后端 未结 2 1071
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-15 10:15

Surface.blit has a new parameter in 1.8: blend. The following values are defined:

  • BLEND_ADD
  • BLEND_SUB
  • BLEND_M
2条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-15 10:46

    You can find the source for the blend operations here: surface.h

    Basically, ADD adds the two source pixels and clips the result at 255. SUB subtracts the two pixels and clips at 0.

    MULT: result = (p1 * p2) / 256

    MIN: Select the lower value of each channel (not the whole pixel), so if pixel1 is (100,10,0) and pixel2 is (0,10,100), you get (0,10,0)

    MAX: Opposite of MIN (i.e. (100,10,100))

    And there is an additional blend mode which isn't obvious from the docs: 0 (or just leave the parameter out). This mode will "stamp" source surface into the destination. If the source surface has an alpha channel, this will be determine how "strong" each pixel is (0=no effect, 255=copy pixel, 128: result = .5*source + .5*destination).

    Useful effects: To darken a certain area, use blend mode 0, fill the source/stamp surface black and set alpha to 10: (0,0,0,10).

    To lighten it, use white (255,255,255,10).

提交回复
热议问题