Home Schedule

Lab 7: Color Change (10 pts)

Setup

  1. Locate your "CS102" folder
  2. Download lab07.zip
  3. Extract the content of the zip file to lab07 in your CS102 folder
  4. Open "lab07.py" with Thonny
  5. READ THE COMMENTS
  6. Submit lab07.py to Moodle when you are finished

Now that we are writing functions, make sure your work today (and all future assignments) follows our class Python style guidelines and you include function comments. Be careful of your indentation!

Assignment

Write a function to edit the following image (this image is already contained in the zip file above as the file shapes.png):

The fuction will be named swap_color. The function will take three parameters. The first parameter will be the picture to edit, the second parameter will be color you want to replace, and the third parameter is the new color. The function will create a copy of the original image and return the modified copy.

Example:

	
	def swap_color(picture, old_color, new_color):
    	   # make a copy of the picture

    	   # modify the copy

    	   # return the copy
	
	

To test your code, the function multiple times to edit each shape in the image and save a copy of the image with the color of ALL THREE shapes changed.

Example:

	
	picture = media.makePicture(filename)
	edited_picture = swap_color(picture, old_color, new_color) # Change square
	edited_picture = swap_color(edited_picture, old_color, new_color) # Change circle
	edited_picture = swap_color(edited_picture, old_color, new_color) # Change triangle
	media.writePictureTo(edited_picture, output_filename)
	
	

Your new image should look something like this, but the choice of color is up to you as long as it is significantly different from the original colors. The filename MUST be called new_shapes.jpg:

DO NOT SUBMIT THE IMAGE FOR THE ASSIGNMENT ONLY THE CODE!

Useful Functions:

You may want to use media.show(picture) or media.explore(picture) to help, but these should NOT appear in the final code submitted.