[Tutor] writing function changeColor

Emile van Sebille emile at fenx.com
Wed Jul 18 21:20:35 CEST 2012


On 7/18/2012 12:07 PM Aditi Pai said...
> Hey Emile! Thanks for the advice. I think maybe I should have combined
> the two parts of my email. The function is just called changeColor. I
> don't actually want to change the color as much as alter the color.

I'm not sure there's a difference...

> I'm working off of this example:
>
> def decreaseRed(picture):
>     for p in getPixels(picture):
>         value=getRed(p)
>         setRed(p,value*0.5)
>
> Except for me, I am asked to also make the argument so that it accepts
> an integer and a float.

So, if by that you mean that the function should accept two passed 
values, one an integer and the other a float, then your def line should 
look like:

def changeColor(myint, myfloat):

If, on the other hand, you want a single passed value that can be either 
an integer or a float you'd just have:

def changeColor(myiint):


> Not sure how to assign different colors and do that.


If the problem if adapting the example so that the function should 
accept both the picture thingy and a value to replace the hardcoded .5, 
your function def might look like:

def changeColor(picture, myRedIntOrFloatVal):

and then swap out the .5 for myRedIntOrFloatVal

What have you written?

Emile



More information about the Tutor mailing list