Change Contents of the Bubble
Welcome to CS1315. Click on the python to add comments.

Looking for the book? They have it at the Engineer's Bookstore at 748 Marietta St NW. Here is there website: http://www.engrbookstore.com/ - Monica

Hotspots: Slides and CodeTA CornerComments?AnnouncementsFAQStatic Webspace
View this PageEdit this PageUploads to this PageHistory of this PageHomeRecent ChangesSearchHelp Guide

transform a picture

# This is a test program that saves us from having to keep typing pickAFile() etc.
# in the command area
def test():
  fileName = pickAFile()
  print fileName
  picture = makePicture(fileName)
  print picture
  show(picture)
  transform(picture)
  repaint(picture)

# This is a function that transforms a picture by changing all the pixels in it in
# exactly the same way.
def transform(pic):
  aBigListOfPixels = getPixels(pic)
  for pixel in aBigListOfPixels:
    pass # Replace this line with the function that transforms the pixel in the right way
             # for example darken(pixel)


def darken(pixel): # Darken a pixel by reducing its RGB values
  setRed(pixel, getRed(pixel)/2)
  setGreen(pixel, getGreen(pixel)/2)
  setBlue(pixel, getBlue(pixel)/2)

def negative(pixel): # Make a pixel its complementary color
  setRed(pixel, 255-getRed(pixel))
  setGreen(pixel, 255-getGreen(pixel))
  setBlue(pixel, 255-getBlue(pixel))

def bw(pixel): #Make a pixel gray
  value = (getRed(pixel)+getGreen(pixel)+getBlue(pixel))/3.0
  grayTone = makeColor(value, value, value)
  setColor(pixel, grayTone)

def bw2(pixel): #Make a pixel gray, simulating an orange contrast filter
  value = (getRed(pixel)*0.5+getGreen(pixel)+getBlue(pixel)*1.5)/3.0
  grayTone = makeColor(value, value, value)
  setColor(pixel, grayTone)

def posterize(pixel): # Change color of pixel to one from a smaller palette
# This posterizing function (unlike the homework) changes all colors into primary
# colors, secondary colors, black, or white.
  if getRed(pixel) > 127:
    setRed(pixel, 255)
  else:
    setRed(pixel, 0)
  if getGreen(pixel) > 127:
    setGreen(pixel, 255)
  else:
    setGreen(pixel, 0)
  if getBlue(pixel) > 127:
    setBlue(pixel, 255)
  else:
    setBlue(pixel, 0)



Link to this Page