# Need to import media to use it's functions
import media
### START OF FUNCTIONS # Set red channel on all pixels to 0
def clearRed(picture):
# Copy the input image
new_pic = media.duplicatePicture(picture)
# Loop through all the pixels in the copy
for pix in media.getPixels(new_pic):
# Change the red channel value
media.setRed(pix, 0)
# Return my edited picture
return new_pic
# Set the green channel on all pixels to 0
def clearGreen(picture): new_pic = media.duplicatePicture(picture) for pix in media.getPixels(new_pic): media.setGreen(pix, 0) return new_pic
# Set the blue channel on all pixels to 0
def clearBlue(picture): new_pic = media.duplicatePicture(picture) for pix in media.getPixels(new_pic): media.setBlue(pix, 0) return new_pic
# Manipulate multiple pixels to create a "sunset" effect
def make_sunset(picture):
# Copy the input image
new_pic = media.duplicatePicture(picture)
# Loop through all the pixels in the copy
for p in media.getPixels(new_pic):
# Set the blue and green channels to be 30% of their value
media.setBlue(p, media.getBlue(p) * 0.7) media.setGreen(p, media.getGreen(p) * 0.7)
# Return my edited picture
return new_pic
# Darken an image
def make_dusk(picture): new_pic = media.duplicatePicture(picture) for p in media.getPixels(new_pic):
# Take a color and darken it (reduce all rgb values)
color = media.makeDarker(media.getColor(p)) media.setColor(p, color) return new_pic
# Brighten an image
def make_sunny(picture): new_pic = media.duplicatePicture(picture) for p in media.getPixels(new_pic):
# Take a color and brighten it (increase all rgb values)
color = media.makeLighter(media.getColor(p)) media.setColor(p, color) return new_pic
# Create a negative of an image
def negative(picture):
# Copy the input image
new_pic = media.duplicatePicture(picture)
# Loop through all the pixels in the copy
for p in media.getPixels(new_pic):
# Set each color channel to be the difference # between the maximum pixel value (255) and # the current channel value.
media.setRed(p, 255 - media.getRed(p)) media.setBlue(p, 255 - media.getBlue(p)) media.setGreen(p, 255 - media.getGreen(p))
# Return my edited picture
return new_pic
## START OF TEST CODE # Filename of the image I wish to use
filename = 'gorge.jpg'
# Load my image based on the filename
picture = media.makePicture(filename)
# Display changed images (DOES NOT SAVE THE IMAGE TO YOUR COMPUTER!)
media.show(clearRed(picture)) media.show(clearGreen(picture)) media.show(clearBlue(picture)) media.show(make_sunset(picture)) media.show(make_dusk(picture)) media.show(make_sunny(picture)) media.show(negative(picture))
# Cleans up media functionality
media.quit()