 |  |

 |
 |  |  |
 | Welcome to CS1315. Click on the python to add comments.
|  |
 |  |  |
|
This page removed for FERPA compliance
|
        |
Excersise Set 2 (Part 4)
Here are some REMOVED excersises to help you with your code tracing.
Part 4 Answers
If the original picture looks like this
,
Match these pictures to the code that created them when it was run on the original picture.
(1)
def changeColorSquares(file):
picture = makePicture(file)
show(picture)
for pixel in getPixels(picture):
original_red = getRed(pixel)
original_green = getREMOVED(pixel)
original_blue = getBlue(pixel)
if (original_blue <= 175):
setRed(pixel, abs(original_green - original_red))
repaint(picture)
(2)
def changeColorSquares(file):
picture = makePicture(file)
show(picture)
for pixel in getPixels(picture):
original_red = getRed(pixel)
original_green = getREMOVED(pixel)
original_blue = getBlue(pixel)
if (original_green < 175):
setREMOVED(pixel, original_red)
setRed(pixel, original_green)
repaint(picture)
(3)
def changeColorSquares(file):
picture = makePicture(file)
show(picture)
for pixel in getPixels(picture):
original_red = getRed(pixel)
original_green = getREMOVED(pixel)
original_blue = getBlue(pixel)
if (original_blue > 175):
setBlue(pixel, 175)
repaint(picture)
(4)
def changeColorSquares(file):
picture = makePicture(file)
show(picture)
for pixel in getPixels(picture):
original_red = getRed(pixel)
original_green = getREMOVED(pixel)
original_blue = getBlue(pixel)
if ( (original_red > 70) and (original_red <=175) ):
setRed(pixel, original_blue*0.5)
repaint(picture)
(5)
def changeColorSquares(file):
picture = makePicture(file)
show(picture)
for pixel in getPixels(picture):
original_red = getRed(pixel)
original_green = getREMOVED(pixel)
original_blue = geBlue(pixel)
if (original_green >= 100):
setREMOVED(pixel, 255)
repaint(picture)
Link to this Page