Python pygame.BLEND_RGBA_MULT Examples
The following are 30
code examples of pygame.BLEND_RGBA_MULT().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
pygame
, or try the search function
.
Example #1
Source File: sprites.py From gamedev with MIT License | 6 votes |
def update(self): self.get_keys() self.rot = (self.rot + self.rot_speed * self.game.dt) % 360 self.image = pg.transform.rotate(self.game.player_img, self.rot) if self.damaged: try: self.image.fill((255, 255, 255, next(self.damage_alpha)), special_flags=pg.BLEND_RGBA_MULT) except: self.damaged = False self.rect = self.image.get_rect() self.rect.center = self.pos self.pos += self.vel * self.game.dt self.hit_rect.centerx = self.pos.x collide_with_walls(self, self.game.walls, 'x') self.hit_rect.centery = self.pos.y collide_with_walls(self, self.game.walls, 'y') self.rect.center = self.hit_rect.center
Example #2
Source File: surface_test.py From fxxkpython with GNU General Public License v3.0 | 6 votes |
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)
Example #3
Source File: surface_test.py From fxxkpython with GNU General Public License v3.0 | 6 votes |
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)
Example #4
Source File: person.py From The-Stolen-Crown-RPG with MIT License | 6 votes |
def damage_animation(self): """ Put a red overlay over sprite to indicate damage. """ if self.damaged: self.image = copy.copy(self.spritesheet_dict['facing left 2']) self.image = pg.transform.scale2x(self.image).convert_alpha() damage_image = copy.copy(self.image).convert_alpha() damage_image.fill((255, 0, 0, self.damage_alpha), special_flags=pg.BLEND_RGBA_MULT) self.image.blit(damage_image, (0, 0)) if self.fade_in: self.damage_alpha += 25 if self.damage_alpha >= 255: self.fade_in = False self.damage_alpha = 255 elif not self.fade_in: self.damage_alpha -= 25 if self.damage_alpha <= 0: self.damage_alpha = 0 self.damaged = False self.fade_in = True self.image = self.spritesheet_dict['facing left 2'] self.image = pg.transform.scale2x(self.image)
Example #5
Source File: person.py From The-Stolen-Crown-RPG with MIT License | 6 votes |
def healing_animation(self): """ Put a green overlay over sprite to indicate healing. """ if self.healing: self.image = copy.copy(self.spritesheet_dict['facing left 2']) self.image = pg.transform.scale2x(self.image).convert_alpha() healing_image = copy.copy(self.image).convert_alpha() healing_image.fill((0, 255, 0, self.healing_alpha), special_flags=pg.BLEND_RGBA_MULT) self.image.blit(healing_image, (0, 0)) if self.fade_in: self.healing_alpha += 25 if self.healing_alpha >= 255: self.fade_in = False self.healing_alpha = 255 elif not self.fade_in: self.healing_alpha -= 25 if self.healing_alpha <= 0: self.healing_alpha = 0 self.healing = False self.fade_in = True self.image = self.spritesheet_dict['facing left 2'] self.image = pg.transform.scale2x(self.image)
Example #6
Source File: sprites.py From gamedev with MIT License | 6 votes |
def update(self): self.get_keys() self.rot = (self.rot + self.rot_speed * self.game.dt) % 360 self.image = pg.transform.rotate(self.game.player_img, self.rot) if self.damaged: try: self.image.fill((255, 255, 255, next(self.damage_alpha)), special_flags=pg.BLEND_RGBA_MULT) except: self.damaged = False self.rect = self.image.get_rect() self.rect.center = self.pos self.pos += self.vel * self.game.dt self.hit_rect.centerx = self.pos.x collide_with_walls(self, self.game.walls, 'x') self.hit_rect.centery = self.pos.y collide_with_walls(self, self.game.walls, 'y') self.rect.center = self.hit_rect.center
Example #7
Source File: surface_test.py From fxxkpython with GNU General Public License v3.0 | 6 votes |
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)
Example #8
Source File: sprites.py From gamedev with MIT License | 6 votes |
def update(self): self.get_keys() self.rot = (self.rot + self.rot_speed * self.game.dt) % 360 self.image = pg.transform.rotate(self.game.player_img, self.rot) if self.damaged: try: self.image.fill((255, 255, 255, next(self.damage_alpha)), special_flags=pg.BLEND_RGBA_MULT) except: self.damaged = False self.rect = self.image.get_rect() self.rect.center = self.pos self.pos += self.vel * self.game.dt self.hit_rect.centerx = self.pos.x collide_with_walls(self, self.game.walls, 'x') self.hit_rect.centery = self.pos.y collide_with_walls(self, self.game.walls, 'y') self.rect.center = self.hit_rect.center
Example #9
Source File: sprites.py From pygame_tutorials with MIT License | 6 votes |
def update(self): self.get_keys() self.rot = (self.rot + self.rot_speed * self.game.dt) % 360 self.image = pg.transform.rotate(self.game.player_img, self.rot) if self.damaged: try: self.image.fill((255, 255, 255, next(self.damage_alpha)), special_flags=pg.BLEND_RGBA_MULT) except: self.damaged = False self.rect = self.image.get_rect() self.rect.center = self.pos self.pos += self.vel * self.game.dt self.hit_rect.centerx = self.pos.x collide_with_walls(self, self.game.walls, 'x') self.hit_rect.centery = self.pos.y collide_with_walls(self, self.game.walls, 'y') self.rect.center = self.hit_rect.center
Example #10
Source File: sprites.py From pygame_tutorials with MIT License | 6 votes |
def update(self): self.get_keys() self.rot = (self.rot + self.rot_speed * self.game.dt) % 360 self.image = pg.transform.rotate(self.game.player_img, self.rot) if self.damaged: try: self.image.fill((255, 255, 255, next(self.damage_alpha)), special_flags=pg.BLEND_RGBA_MULT) except: self.damaged = False self.rect = self.image.get_rect() self.rect.center = self.pos self.pos += self.vel * self.game.dt self.hit_rect.centerx = self.pos.x collide_with_walls(self, self.game.walls, 'x') self.hit_rect.centery = self.pos.y collide_with_walls(self, self.game.walls, 'y') self.rect.center = self.hit_rect.center
Example #11
Source File: sprites.py From pygame_tutorials with MIT License | 6 votes |
def update(self): self.get_keys() self.rot = (self.rot + self.rot_speed * self.game.dt) % 360 self.image = pg.transform.rotate(self.game.player_img, self.rot) if self.damaged: try: self.image.fill((255, 255, 255, next(self.damage_alpha)), special_flags=pg.BLEND_RGBA_MULT) except: self.damaged = False self.rect = self.image.get_rect() self.rect.center = self.pos self.pos += self.vel * self.game.dt self.hit_rect.centerx = self.pos.x collide_with_walls(self, self.game.walls, 'x') self.hit_rect.centery = self.pos.y collide_with_walls(self, self.game.walls, 'y') self.rect.center = self.hit_rect.center
Example #12
Source File: sprites.py From pygame_tutorials with MIT License | 6 votes |
def update(self): self.get_keys() self.rot = (self.rot + self.rot_speed * self.game.dt) % 360 self.image = pg.transform.rotate(self.game.player_img, self.rot) if self.damaged: try: self.image.fill((255, 255, 255, next(self.damage_alpha)), special_flags=pg.BLEND_RGBA_MULT) except: self.damaged = False self.rect = self.image.get_rect() self.rect.center = self.pos self.pos += self.vel * self.game.dt self.hit_rect.centerx = self.pos.x collide_with_walls(self, self.game.walls, 'x') self.hit_rect.centery = self.pos.y collide_with_walls(self, self.game.walls, 'y') self.rect.center = self.hit_rect.center
Example #13
Source File: surface_test.py From fxxkpython with GNU General Public License v3.0 | 6 votes |
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)
Example #14
Source File: sprites.py From gamedev with MIT License | 6 votes |
def update(self): self.get_keys() self.rot = (self.rot + self.rot_speed * self.game.dt) % 360 self.image = pg.transform.rotate(self.game.player_img, self.rot) if self.damaged: try: self.image.fill((255, 255, 255, next(self.damage_alpha)), special_flags=pg.BLEND_RGBA_MULT) except: self.damaged = False self.rect = self.image.get_rect() self.rect.center = self.pos self.pos += self.vel * self.game.dt self.hit_rect.centerx = self.pos.x collide_with_walls(self, self.game.walls, 'x') self.hit_rect.centery = self.pos.y collide_with_walls(self, self.game.walls, 'y') self.rect.center = self.hit_rect.center
Example #15
Source File: surface_test.py From fxxkpython with GNU General Public License v3.0 | 5 votes |
def test_fill(self): 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 for y in range(5, 480, 10): self.assertEqual(screen.get_at((10, y)), screen.get_at((330, 480 - y)))
Example #16
Source File: surface_test.py From fxxkpython with GNU General Public License v3.0 | 5 votes |
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()
Example #17
Source File: surface_test.py From fxxkpython with GNU General Public License v3.0 | 5 votes |
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)
Example #18
Source File: surface_test.py From fxxkpython with GNU General Public License v3.0 | 5 votes |
def test_fill(self): 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 for y in range(5, 480, 10): self.assertEqual(screen.get_at((10, y)), screen.get_at((330, 480 - y)))
Example #19
Source File: surface_test.py From fxxkpython with GNU General Public License v3.0 | 5 votes |
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()
Example #20
Source File: surface_test.py From fxxkpython with GNU General Public License v3.0 | 5 votes |
def test_fill(self): 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 for y in range(5, 480, 10): self.assertEqual(screen.get_at((10, y)), screen.get_at((330, 480 - y)))
Example #21
Source File: surface_test.py From fxxkpython with GNU General Public License v3.0 | 5 votes |
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()
Example #22
Source File: surface_test.py From fxxkpython with GNU General Public License v3.0 | 5 votes |
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)
Example #23
Source File: surface_test.py From fxxkpython with GNU General Public License v3.0 | 5 votes |
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()
Example #24
Source File: surface_test.py From fxxkpython with GNU General Public License v3.0 | 5 votes |
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)
Example #25
Source File: road.py From Reinforcement-Learning-for-Self-Driving-Cars with Apache License 2.0 | 5 votes |
def blit_mask(source, dest, destpos, mask, maskrect): """ Blit an source image to the dest surface, at destpos, with a mask, using only the maskrect part of the mask. """ tmp = source.copy() tmp.blit(mask, maskrect.topleft, maskrect, special_flags=pygame.BLEND_RGBA_MULT) dest.blit(tmp, destpos, dest.get_rect().clip(maskrect))
Example #26
Source File: earth.py From code-jam-5 with MIT License | 5 votes |
def __draw_polution(self) -> None: """Draw ozone layer and polution (yellow tint).""" # Ozone layer - horizontal line, transparency depends on current heat. ozone_alpha = fit_to_range(game_vars.current_heat, 0, MAX_HEAT, 0, 50) _ozone = self.ozone_image.copy() _ozone.fill((255, 255, 255, ozone_alpha), None, pg.BLEND_RGBA_MULT) # Polution - yellow transparent background fill indicating toxic air. polution_alpha = fit_to_range(game_vars.current_heat, 0, MAX_HEAT, 0, 150) self.polution_image.set_alpha(polution_alpha) self.screen.blit(self.polution_image, self.polution_pos) self.screen.blit(_ozone, self.ozone_pos)
Example #27
Source File: pygamefont.py From DanceCV with BSD 3-Clause "New" or "Revised" License | 5 votes |
def render(self, text, antialias=False, color=(255,255,255), background=None): if not text: return None ci = [ self.chars[character] for character in text ] width = sum( c['xadvance'] for c in ci ) + ci[-1]['xoffset'] height = max( c['height'] + c['yoffset'] for c in ci ) surf = pygame.Surface((width, height), flags=pygame.SRCALPHA) x = 0 for c in ci: page = self.pages[c['page']] w, h = c['width'], c['height'] sx, sy = c['x'], c['y'] xofs = c['xoffset'] yofs = c['yoffset'] surf.blit(page, (x + xofs, yofs, w, h), (sx, sy, w, h)) x = x + c['xadvance'] surf.fill(color, special_flags=pygame.BLEND_RGBA_MULT) if(background): newsurf = pygame.Surface((width, height), flags=pygame.SRCALPHA) newsurf.fill(background) newsurf.blit(surf, (0,0)) surf = newsurf return surf
Example #28
Source File: lcars_widgets.py From rpi_lcars with MIT License | 5 votes |
def __init__(self, colour, style, pos, handler=None): image = pygame.image.load("assets/elbow.png").convert_alpha() # alpha=255 # image.fill((255, 255, 255, alpha), None, pygame.BLEND_RGBA_MULT) if (style == LcarsElbow.STYLE_BOTTOM_LEFT): image = pygame.transform.flip(image, False, True) elif (style == LcarsElbow.STYLE_BOTTOM_RIGHT): image = pygame.transform.rotate(image, 180) elif (style == LcarsElbow.STYLE_TOP_RIGHT): image = pygame.transform.flip(image, True, False) self.image = image size = (image.get_rect().width, image.get_rect().height) LcarsWidget.__init__(self, colour, pos, size, handler) self.applyColour(colour)
Example #29
Source File: renderer.py From pypownet with GNU Lesser General Public License v3.0 | 5 votes |
def draw_plot_game_over(): game_over_font = pygame.font.SysFont("Arial", 25) red = (255, 26, 26) txt_surf = game_over_font.render('game over', False, (255, 255, 255)) alpha_img = pygame.Surface(txt_surf.get_size(), pygame.SRCALPHA) alpha_img.fill(red + (128,)) # txt_surf.blit(alpha_img, (0, 0), special_flags=pygame.BLEND_RGBA_MULT) game_over_surface = pygame.Surface((200, 70), pygame.SRCALPHA, 32).convert_alpha() game_over_surface.fill(red + (128,)) game_over_surface.blit(txt_surf, (38, 18)) return game_over_surface
Example #30
Source File: renderer.py From pypownet with GNU Lesser General Public License v3.0 | 5 votes |
def draw_plot_pause(): pause_font = pygame.font.SysFont("Arial", 25) yellow = (255, 255, 179) txt_surf = pause_font.render('pause', False, (80., 80., 80.)) alpha_img = pygame.Surface(txt_surf.get_size(), pygame.SRCALPHA) alpha_img.fill(yellow + (72,)) # txt_surf.blit(alpha_img, (0, 0), special_flags=pygame.BLEND_RGBA_MULT) pause_surface = pygame.Surface((200, 70), pygame.SRCALPHA, 32).convert_alpha() pause_surface.fill(yellow + (128,)) pause_surface.blit(txt_surf, (64, 18)) return pause_surface