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 Page (locked)Uploads to this PageHistory of this PageHomeRecent ChangesSearchHelp Guide

Excersise Set 2 (Part 5)

Part 5 Answers
Match the original and its modified image to the code that created the modified copy.


















Originals External Image External Image External Image External Image External Image
Modified External Image External Image External Image External Image External Image

















(1)
def changeColorSquares(file):
  picture = makePicture(file)
  openPictureTool(picture)

  for pixel in getPixels(picture):
    r = getRed(pixel) 
    g = getGreen(pixel)
    b = getBlue(pixel)

    if ( (r > 130) and (g < 200) and (b < 200) ):
      setRed(pixel, 0)
      setGreen(pixel, 0)
      setBlue(pixel, 255)
    else:
      if ( (r < 130) and (g < 200) and (b < 200) ):
        setRed(pixel, 255)
        setGreen(pixel, 255)
        setBlue(pixel, 0)
        
  repaint(picture)


(2)
def changeColorSquares(file):
  picture = makePicture(file)
  openPictureTool(picture)

  for pixel in getPixels(picture):
    r = getRed(pixel) 
    g = getGreen(pixel)
    b = getBlue(pixel)

    new_color = makeColor(255-r, 255-g, 255-b)
    setColor(pixel, new_color)

  repaint(picture)


(3)
def changeColorSquares(file):
  picture = makePicture(file)
  openPictureTool(picture)

  for pixel in getPixels(picture):
    r = getRed(pixel) 
    g = getGreen(pixel)
    b = getBlue(pixel)

    if ( (r < 100) and (g < 100) and (b>10) ):
      setRed(pixel, 128)
      setGreen(pixel, 128)
      setBlue(pixel, 128)
 
  repaint(picture)


(4)
def changeColorSquares(file):
  picture = makePicture(file)
  openPictureTool(picture)

  for pixel in getPixels(picture):
    r = getRed(pixel) 
    g = getGreen(pixel)
    b = getBlue(pixel)

    if ( (r < 100) and (g < 100) and (b > 10) ):
      setRed(pixel, 255)
      setGreen(pixel, 255)
      setBlue(pixel, 0)
    else:
      if ( (r > 10) and (g < 100) and (b < 100) ):
       setRed(pixel, 0)
       setGreen(pixel, 255)
       setBlue(pixel, 0)

  repaint(picture)


(5)
def changeColorSquares(file):
  picture = makePicture(file)
  openPictureTool(picture)

  for pixel in getPixels(picture):
    r = getRed(pixel) 
    g = getGreen(pixel)
    b = getBlue(pixel)

    if ( (r > 175) and (g < 215) ):
      setRed(pixel, 0)
      setGreen(pixel, 255)
      setBlue(pixel, 255)
    else:
      if ( (r < 200) and (g < 200) and (b < 200) ):
        setRed(pixel, 255)
        setGreen(pixel, 255)
        setBlue(pixel, 0)

  repaint(picture)

 


Link to this Page