surface color swap

This commit is contained in:
Frank DeMarco 2015-08-13 05:17:53 -04:00
parent a0aba9a0bb
commit 1fcfbb3211
1 changed files with 8 additions and 1 deletions

View File

@ -1,7 +1,7 @@
from random import randint
from math import sin, cos, atan2, radians, sqrt
from pygame import Surface
from pygame import Surface, PixelArray
from pygame.locals import *
def get_step(start, end, speed):
@ -128,3 +128,10 @@ def render_box(font, text, antialias, color, background=None, border=None,
bordered_surface.blit(surface, rect)
surface = bordered_surface
return surface
def get_color_swapped_surface(surface, current, replacement):
swapped = surface.copy()
pixels = PixelArray(swapped)
pixels.replace(current, replacement)
del pixels
return swapped