Skip to content

Instantly share code, notes, and snippets.

@jamesnvc
Created September 24, 2010 03:21
Show Gist options
  • Save jamesnvc/594813 to your computer and use it in GitHub Desktop.
Save jamesnvc/594813 to your computer and use it in GitHub Desktop.
import media
COLOUR_MAX = 255
COLOUR_MIN = 0
def get_picture():
'''Solicit user input to select a file and load it as a Picture.
Return the Picture.
'''
filename= media.choose_file()
pic = media.load_picture(filename)
return pic
def set_colour(picture, colour, value):
for pixel in picture:
getattr(media, 'set_%s' % colour)(pixel, value)
def maximize_red(pic):
'''Maximize the red component of every pixel in the Picture pic.
'''
set_colour(pic, 'red', COLOUR_MAX)
def remove_blue(pic):
set_colour(pic, 'blue', COLOUR_MIN)
def halve_green(pic):
set_colour(pic, 'green', COLOUR_MAX/2)
if __name__ == '__main__':
pic = get_picture()
maximize_red(pic)
remove_blue(pic)
halve_green(pic)
media.show(pic)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment