April 24, 2010: We are pleased to announce that Version 4 of this course is now under development. For updates and an early peek at the content, please check out the Software Carpentry blog at http://www.software-carpentry.org/blog/.
Figure 8.1: Pixels in a Picture
Figure 8.2: Color Combinations
media.create_picture(width, height, color)media.choose_file()media.load_picture(filename)media.show(pic)media.get_width(pic)media.get_height(pic)pixel = media.get_pixel(pic, x, y)c = media.get_color(pixel)media.set_color(pixel, c)media.get_green(pixel)media.set_green(pixel, g)c = media.create_color(r, g, b)import media
import color
pic = media.create_picture(100, 200, media.black)
for i in range(media.get_width(pic)):
for j in range(media.get_height(pic)):
pixel = media.get_pixel(pic, i, j)
media.set_color(pixel,
media.create_color(i % 255, j % 255, 0))
pic.show()
For each pixel in pic: get the blue component of the pixel reduce that number by 30% set the blue component of the pixel to the reduced number get the green component of the pixel reduce that number by 30% set the green component of the pixel to the reduced number
Copyright © 2005-09 Python Software Foundation.
Created Thu Aug 6 21:56:06 2009 UTC