In this lab you will become more familiar with using Python for
loops
to manipulate colors in a picture.
increaseRed
and reduceRed
increaseRed
and reduceRed
functions are
so similar, that we might ask why there are two different functions at all. Create
a new function (for example, by copying and pasting either one of them) that
takes an additional parameter representing the multiplier to use
when modifying the amount of red in a picture.
Design Questions: What would be a clear, meaningful name for your new function? What would be a clear, meaningful name for the new parameter?Use the parameter rather than a constant multiplier value in the body of the function.
increaseRed
and reduceRed
functions.
makeSunset
function from the previous
mini-lab so that instead of looping through all the pixels and changing
their green and blue values, it just calls
your new, generalized
functions. These new functions will take care of the looping and
color changing. Test your modified function by loading and running it.
Debugging Tips: Remember that your new functions will return a new picture with the colors modified. So, after you change the green values in the picture, you need to make sure you pass the result you got from that function into the function to change the blue values. You will then return the picture that gets returned from the function that changes the blue values.
Analysis Questions: Is
it necessary to create a new picture that is a duplicate of the original
picture in the beginning of the makeSunset
function anymore? Why or
why not? If it is not necessary, remove that code from your function.
makeSunset
function with a number of
different pictures. Choose one that you particularly like. We are
going to save it
using the jes4py writePictureTo
function.
For example, suppose my picture was captured in the variable
myPict
. To save this picture as a JPEG image on a PC, I would type
writePictureTo(myPict,
pickAFile())
When the file selector window opens, I would navigate to the folder
where I want to save the image. I would then type in a name for the
image, such as sunsetPic.jpg
. Be sure to include the
.jpg
file extension so that it gets saved as an image file.
To save this picture as a JPEG, I would type
writePictureTo(myPict,
pickAFolder()+"sunsetPic.jpg")
where sunsetPic.jpg
is whatever you want to name the image
file. When the folder selector window opens, I would navigate to the folder
where I want to save the image.
negative
, grayscale
and
weightedGrayscale
functions from the Pictures and Loops notes.
For each function, create and save a modified picture.
redSkyEffect
. Add a comment at the top of
the function to describe what it does.
Save a picture you created using your new function.