Skip to content

Instantly share code, notes, and snippets.

@vane90
Created February 4, 2013 22:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vane90/4710424 to your computer and use it in GitHub Desktop.
Save vane90/4710424 to your computer and use it in GitHub Desktop.
import pygame, sys, os
from pygame.locals import *
from sys import argv
import Image
def pixel():
ima = argv[1]
im = Image.open(ima)
imagen=im.load()
ancho, alto = im.size
for i in range(ancho):
for j in range(alto):
(r,g,b)= im.getpixel((i,j))
pix = (r + g + b)/3
imagen[i,j]=(pix, pix, pix)
nueva= 'nueva.png'
im.save(nueva)
return nueva
def main():
pygame.init()
screen = pygame.display.set_mode((500, 300))
pygame.display.set_caption('Escala de Grises')
imagen = pixel()
img = pygame.image.load(imagen)
screen = pygame.display.get_surface()
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit()
screen.blit(img, (0,0))
pygame.display.update()
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment