# Code from Lecture on 2/8/2007 # First attempt at making a sunset # This may cause overflow with the red color amount def makeSunset1(): # get the picture file = pickAFile () pict = makePicture(file) openPictureTool (pict) # loop for each pixel in the picture for pix in getPixels (pict): # modify the red amount in each pixel value = getRed (pix) # multiplying by 1.25 may result in overflow # if the red value is already very large newValue = value * 1.25 setRed (pix, newValue) # show the resulting image openPictureTool (pict) # Second and better attempt at making a sunset def makeSunset2(): file = pickAFile () pict = makePicture(file) openPictureTool (pict) for pix in getPixels (pict): value = getGreen (pix) newValue = value * 0.7 setGreen (pix, newValue) value = getBlue (pix) newValue = value * 0.7 setBlue (pix, newValue) openPictureTool (pict) # Make a color negative image def makeNegative(): file = pickAFile () pict = makePicture(file) openPictureTool (pict) for pix in getPixels (pict): redAmount = getRed (pix) greenAmount = getGreen (pix) blueAmount = getBlue (pix) negColor = makeColor (255-redAmount,255-greenAmount, 255-blueAmount) setColor(pix, negColor) openPictureTool (pict) # Make a color negative image def makeNegative2(): file = pickAFile () pict = makePicture(file) openPictureTool (pict) for pix in getPixels (pict): redAmount = getRed (pix) greenAmount = getGreen (pix) blueAmount = getBlue (pix) negColor = makeColor (255-redAmount,255-greenAmount, 255-blueAmount) setColor(pix, negColor) # show the negative image openPictureTool (pict) for pix in getPixels (pict): redAmount = getRed (pix) greenAmount = getGreen (pix) blueAmount = getBlue (pix) negColor = makeColor (255-redAmount,255-greenAmount, 255-blueAmount) setColor(pix, negColor) # show of negative-negative image (should be back to the original) openPictureTool (pict) def getPicture(): file = pickAFile (); pict = makePicture(file); openPictureTool (pict) def turnRed(): brown = makeColor(122,86,62) file = pickAFile() picture = makePicture(file) for px in getPixels(picture): color = getColor(px) if distance(color,brown) < 25.0: redness = getRed(px)*1.5 setRed(px,redness) show(picture) return(picture)