Last active
April 18, 2018 23:40
-
-
Save illume/e7c06e2791dfab3010eabd46daf2ebc1 to your computer and use it in GitHub Desktop.
Shows the invert function.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import pygame as pg | |
main_dir = os.path.split(os.path.abspath(__file__))[0] | |
# data_dir = os.path.join(main_dir, 'data') | |
data_dir = main_dir | |
def show(image): | |
screen = pg.display.get_surface() | |
screen.fill((0, 255, 255)) | |
screen.blit(image, (0, 0)) | |
pg.display.flip() | |
while 1: | |
event = pg.event.wait() | |
if event.type == pg.QUIT: | |
raise SystemExit | |
if event.type == pg.MOUSEBUTTONDOWN or event.type == pg.KEYDOWN: | |
break | |
def invert(surface): | |
'Black changed to white. Others changed to black.' | |
for x in range(surface.get_width()): | |
for y in range(surface.get_height()): | |
r,g,b,a = surface.get_at((x, y)) | |
if (r,g,b) == (0, 0, 0): | |
r,g,b = (255,255,255) | |
elif (r,g,b) == (255,255,255): | |
r,g,b = (0, 0, 0) | |
surface.set_at((x, y), (r, g, b, a)) | |
return surface | |
def main(): | |
pg.init() | |
pg.display.set_mode((255, 255)) | |
pg.display.flip() | |
if not os.path.exists('pidle_3.png'): | |
os.system('wget https://cdn.discordapp.com/attachments/336104478644240394/436304548517380105/pidle_3.png') | |
surface = pg.image.load(os.path.join(data_dir, 'pidle_3.png')) | |
surface = surface.convert_alpha() | |
show(surface) | |
show(invert(surface)) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment