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

purple rinse and hair transplant

def purpleRinse(picture, hairColor, x1, y1, x2, y2):
  for x in range(x1, x2+1):
    for y in range(y1, y2+1):
      pixel = getPixel(picture, x, y)
      pixColor = getColor(pixel)
      if distance(pixColor, hairColor) < 40: # May need to change threshold for other faces
        setRed(pixel, getRed(pixel)*1.5) # Make it redder
        setBlue(pixel, getBlue(pixel)*1.8) # Make it even bluer
      else:
        setColor(pixel, white)

def transplantHair(hairPic, baldPic, xOffset, yOffset, x1, y1, x2, y2):
 w = getWidth(baldPic)
 h = getHeight(baldPic)
 for x in range(x1, x2+1):
    for y in range(y1, y2+1):
      fromPixel = getPixel(hairPic, x, y)
      # Rather than work out what was wrong, I just defined destination x and y coords
      # There must have been a typo in my offset subtraction code.....duh.
      destX = x-xOffset 
      destY = y-yOffset
      if destX > 0 and destX < w and destY > 0 and destY < h:
        toPixel = getPixel(baldPic, destX, destY)
        fromColor = getColor(fromPixel)
        if fromColor <> white:
          setColor(toPixel, fromColor)
  

def test():
  filename1 = '/Users/potts/Pictures/Snaps/lesley.jpg'
  pic1 = makePicture(filename1)
  show(pic1)
  hc = makeColor(75, 70, 25)
  purpleRinse(pic1, hc, 71, 19, 394, 239)
  repaint(pic1)
  filename2 = '/Users/potts/Pictures/Snaps/self.jpg'
  pic2 = makePicture(filename2)
  show(pic2)
  transplantHair(pic1, pic2, 205-119, 37-39, 71, 19, 394, 239) # I also tweaked the offsets so that the faces are better aligned.
  repaint(pic2)



Link to this Page