Python Loops And Images Lab Page 3

ADVERTISEMENT

# (The path where your files are located for this exercise.)
# This function sets the path used to find and or save your files and allows you to use the
# getMediaPath() function instead of typing in the complete path to your files.
#2. Ask the user for a name for the file.
fileName = requestString("Type in a file name to save your image of the stick people? (ie. stickPeople.jpg)")
#3. Use the filename in the writePictureTo function as shown below.
# The getMediaPath() function will be used to determine where to store your file.
writePictureTo(canvas, getMediaPath(fileName))
Exercise 3. Create a Python function called greenToBlueAndBlackToRed that takes one picture object
parameter. Your function should change the color of all green pixels to blue and all black pixels should be set
to the color red. Use the getPixels function to create a list of all of the pixels in the picture and then use a for
loop to examine each one and change the color if it is green or black. … for aPixel in listOfAllPixels:
When you write the code in main() to test your function, use the file named greenEyes.bmp as your original
image. Once you have that working as desired, add two more lines of code to main() to save the new image.
(Ask the user for the name of the file and then use the writePictureTo function to save it in your Lab folder. For
this exercise name your file blueEyes.bmp)
.
Show your TA or Lab Instructor your work when you are finished and remember to hand in your program to the
N:\HandIns\CS150 folder.

ADVERTISEMENT

00 votes

Related Articles

Related forms

Related Categories

Parent category: Education
Go
Page of 3