def test_blend_rgba(self):
bitsizes = [16, 32]
blends = ['BLEND_RGBA_ADD',
'BLEND_RGBA_SUB',
'BLEND_RGBA_MULT',
'BLEND_RGBA_MIN',
'BLEND_RGBA_MAX']
for bitsize in bitsizes:
surf = self._make_surface(bitsize, srcalpha=True)
comp = self._make_surface(bitsize, srcalpha=True)
for blend in blends:
self._fill_surface(surf)
self._fill_surface(comp)
comp.blit(surf, (3, 0),
special_flags=getattr(pygame, blend))
surf.blit(surf, (3, 0),
special_flags=getattr(pygame, blend))
self._assert_same(surf, comp)
python类BLEND_RGBA_MULT的实例源码
def __drawAllSprites(self):
'''
Private Funktion - nicht ausserhalb der Klasse benutzen!
zeichnet die Sprites
Parameter: -
return values: -
'''
#self.allPlayers.draw(self.screen)
self.drawBots.draw(self.screen)
self.allBullets.draw(self.screen)
if int(self.player1.room) == 0:
self.allWeapons.draw(self.screen)
self.allDoors0.draw(self.screen)
self.screen.blit(self.shaderScreen, (0,0), special_flags = pygame.BLEND_RGBA_MULT)
#self.allDoors.draw(self.screen)
else:
self.allDoors1.draw(self.screen)
def __init__(self, image, origin, tints,
blit_flags=0, tint_flags=pygame.BLEND_RGBA_MULT):
"""Initialize the artist.
Arguments:
image (pygame.Surface): Image to draw for each particle.
tints (list of 4-tuple colors): Contains multiple 4-tuples,
each of which indicates an RGBA tint to apply to the image.
There should be at least two tints: if two are provided,
the image will fade from the first tint to the second
over its lifetime (determined by
`particle.life / particle.initial_life`). If more than two
are given, particle will fade between different tints by
dividing lifetime equally; so for 4 tints, particle will spend
1/3 its lifetime between the first two, 1/3 between
the middle two, and 1/3 between the last two.
blit_flags (int): special flags determining blit mode (normal,
additive, subtractive, etc) the tinted image will be applied
to the surface. By default this is normal -- apply the
image while respecting alpha, etc.)
tint_flags (int): special flags determining blit mode (normal,
additive, subtractive, etc) the tint will be applied to
the image. By default this is multiplicative.
"""
self.image = image
try:
self.image = self.image.convert_alpha()
except: # pragma: no cover
pass
if callable(origin):
self.origin = origin(self.image)
else:
self.origin = origin
self.tints = tints
self.blit_flags = blit_flags
self.tint_flags = tint_flags
def apply(self, img, n=0):
srf = self.srfSize(img)
color = [round(c + (255 - c) * n) for c in self.color]
srf.fill(color, None, pygame.BLEND_RGBA_MULT)
return img
def todo_test_blit(self):
# __doc__ (as of 2008-08-02) for pygame.surface.Surface.blit:
# Surface.blit(source, dest, area=None, special_flags = 0): return Rect
# draw one image onto another
#
# Draws a source Surface onto this Surface. The draw can be positioned
# with the dest argument. Dest can either be pair of coordinates
# representing the upper left corner of the source. A Rect can also be
# passed as the destination and the topleft corner of the rectangle
# will be used as the position for the blit. The size of the
# destination rectangle does not effect the blit.
#
# An optional area rectangle can be passed as well. This represents a
# smaller portion of the source Surface to draw.
#
# An optional special flags is for passing in new in 1.8.0: BLEND_ADD,
# BLEND_SUB, BLEND_MULT, BLEND_MIN, BLEND_MAX new in 1.8.1:
# BLEND_RGBA_ADD, BLEND_RGBA_SUB, BLEND_RGBA_MULT, BLEND_RGBA_MIN,
# BLEND_RGBA_MAX BLEND_RGB_ADD, BLEND_RGB_SUB, BLEND_RGB_MULT,
# BLEND_RGB_MIN, BLEND_RGB_MAX With other special blitting flags
# perhaps added in the future.
#
# The return rectangle is the area of the affected pixels, excluding
# any pixels outside the destination Surface, or outside the clipping
# area.
#
# Pixel alphas will be ignored when blitting to an 8 bit Surface.
# special_flags new in pygame 1.8.
self.fail()
def test_fill_blend_rgba(self):
destinations = [self._make_surface(8),
self._make_surface(16),
self._make_surface(16, srcalpha=True),
self._make_surface(24),
self._make_surface(32),
self._make_surface(32, srcalpha=True)]
blend = [('BLEND_RGBA_ADD', (0, 25, 100, 255),
lambda a, b: min(a + b, 255)),
('BLEND_RGBA_SUB', (0, 25, 100, 255),
lambda a, b: max(a - b, 0)),
('BLEND_RGBA_MULT', (0, 7, 100, 255),
lambda a, b: (a * b) // 256),
('BLEND_RGBA_MIN', (0, 255, 0, 255), min),
('BLEND_RGBA_MAX', (0, 255, 0, 255), max)]
for dst in destinations:
dst_palette = [dst.unmap_rgb(dst.map_rgb(c))
for c in self._test_palette]
for blend_name, fill_color, op in blend:
fc = dst.unmap_rgb(dst.map_rgb(fill_color))
self._fill_surface(dst)
p = []
for dc in dst_palette:
c = [op(dc[i], fc[i]) for i in range(4)]
if not dst.get_masks()[3]:
c[3] = 255
c = dst.unmap_rgb(dst.map_rgb(c))
p.append(c)
dst.fill(fill_color, special_flags=getattr(pygame, blend_name))
self._assert_surface(dst, p, ", %s" % blend_name)
def test_fill(self):
pygame.init()
try:
screen = pygame.display.set_mode((640, 480))
# Green and blue test pattern
screen.fill((0, 255, 0), (0, 0, 320, 240))
screen.fill((0, 255, 0), (320, 240, 320, 240))
screen.fill((0, 0, 255), (320, 0, 320, 240))
screen.fill((0, 0, 255), (0, 240, 320, 240))
# Now apply a clip rect, such that only the left side of the
# screen should be effected by blit opperations.
screen.set_clip((0, 0, 320, 480))
# Test fills with each special flag, and additionaly without any.
screen.fill((255, 0, 0, 127), (160, 0, 320, 30), 0)
screen.fill((255, 0, 0, 127), (160, 30, 320, 30), pygame.BLEND_ADD)
screen.fill((0, 127, 127, 127), (160, 60, 320, 30), pygame.BLEND_SUB)
screen.fill((0, 63, 63, 127), (160, 90, 320, 30), pygame.BLEND_MULT)
screen.fill((0, 127, 127, 127), (160, 120, 320, 30), pygame.BLEND_MIN)
screen.fill((127, 0, 0, 127), (160, 150, 320, 30), pygame.BLEND_MAX)
screen.fill((255, 0, 0, 127), (160, 180, 320, 30), pygame.BLEND_RGBA_ADD)
screen.fill((0, 127, 127, 127), (160, 210, 320, 30), pygame.BLEND_RGBA_SUB)
screen.fill((0, 63, 63, 127), (160, 240, 320, 30), pygame.BLEND_RGBA_MULT)
screen.fill((0, 127, 127, 127), (160, 270, 320, 30), pygame.BLEND_RGBA_MIN)
screen.fill((127, 0, 0, 127), (160, 300, 320, 30), pygame.BLEND_RGBA_MAX)
screen.fill((255, 0, 0, 127), (160, 330, 320, 30), pygame.BLEND_RGB_ADD)
screen.fill((0, 127, 127, 127), (160, 360, 320, 30), pygame.BLEND_RGB_SUB)
screen.fill((0, 63, 63, 127), (160, 390, 320, 30), pygame.BLEND_RGB_MULT)
screen.fill((0, 127, 127, 127), (160, 420, 320, 30), pygame.BLEND_RGB_MIN)
screen.fill((255, 0, 0, 127), (160, 450, 320, 30), pygame.BLEND_RGB_MAX)
# Update the display so we can see the results
pygame.display.flip()
# Compare colors on both sides of window
y = 5
while y < 480:
self.assertEquals(screen.get_at((10, y)),
screen.get_at((330, 480 - y)))
y += 10
finally:
pygame.quit()
def main():
pygame.init()
pygame.font.init()
screen = init_screen(*screen_size)
font = pygame.font.Font(font_name, font_size)
clock = pygame.time.Clock()
compute_curve()
generate_images(font)
init_grid(*screen_size)
frame_number = 0
running = True
while running:
if not save_to_disk:
clock.tick(60)
for event in pygame.event.get():
if event.type == pygame.VIDEORESIZE:
if not screen_size == (event.w, event.h):
screen = init_screen(event.w, event.h)
init_grid(event.w, event.h)
burn_set.clear()
elif event.type == pygame.QUIT:
running = False
update_burners()
# update and draw grid to the screen
screen_blit = screen.blit
for glyph in (i for i in glyphs if i.ttl):
# have random chance to change the glyph
if random() > .9:
glyph.index = randrange(len(charset))
# update the glyphs's life and image
# if it becomes 0, then it won't be updated next frame
glyph.ttl -= 1
# get image and draw it
screen_blit(cache[glyph.index][glyph.ttl], glyph.pos)
screen_blit(logo, (0, 0), None, pygame.BLEND_RGBA_MULT)
if save_to_disk:
filename = "snapshot%05d.tga" % frame_number
pygame.image.save(screen, filename)
frame_number += 1
else:
pygame.display.flip()
def getOverlay(self, rect):
"""
Draw the ShaderOverlay and return the result
parameters: pygame.Rect bounds of the Overlay
return values: pygame.Surface the result
"""
try:
surface = pygame.Surface(rect.size, pygame.SRCALPHA, 32)
except:
return pygame.Surface((0, 0), pygame.SRCALPHA, 32)
surface.fill(self._background)
shapes = pygame.Surface(rect.size, pygame.SRCALPHA, 32)
lightsources = pygame.Surface(rect.size, pygame.SRCALPHA, 32)
removeAfter = []
for ls in self._lightsources:
quality = self._lightsources[ls][3]
intensity = self._lightsources[ls][2]
color = self._lightsources[ls][1]
radius = self._lightsources[ls][0]
r = ls.rect
polygon = []
try:
for x in xrange(1, 2 * radius + r.w, quality):
polygon.append(self.raycast(r.center, (r.left - radius + x, r.top - radius), rect, radius))
for y in xrange(1, 2 * radius + r.h, quality):
polygon.append(self.raycast(r.center, (r.right + radius, r.top - radius + y), rect, radius))
for x in xrange(1, 2 * radius + r.w, quality):
polygon.append(self.raycast(r.center, (r.right + radius - x, r.bottom + radius), rect, radius))
for y in xrange(1, 2 * radius + r.h, quality):
polygon.append(self.raycast(r.center, (r.left - radius, r.bottom + radius - y), rect, radius))
except:
removeAfter.append(ls)
if polygon:
pygame.draw.polygon(shapes, color, polygon)
gradient = pygame.Surface(rect.size, pygame.SRCALPHA, 32)
try:
for n in range(2 * radius, 0, -1):
alpha = intensity - int(intensity * (float(n) / (2 * radius)))
pygame.draw.ellipse(gradient, color + (alpha,), r.inflate(n, n))
except:
removeAfter.append(ls)
shapes.blit(gradient, (0, 0), special_flags = pygame.BLEND_RGBA_MULT)
lightsources.blit(shapes, (0, 0), special_flags = pygame.BLEND_RGBA_MAX)
surface.blit(lightsources, (0, 0))
for ls in removeAfter:
self.removeLightsource(ls)
return surface