On 2:59 PM, Joe Ohmer wrote:
Hello,
The following code works well but I don't understand why the mysteryEffect code
block changes the picture.
Doesn’t 64*(r/64) just equal r? (Same with g and b.) So this function should
not change the picture at all. But it does! If anyone can explain how and why
this actually changes the picture I would appreciate it greatly.
<snip>
#Adds a rainbow effect to the picture
def mysteryEffect( pic2 ):
for px in getPixels( pic2 ):
r= getRed ( px )
g= getGreen( px )
b= getBlue( px )
setRed( px, 64*(r/64))
setGreen( px, 64*(g/64))
setBlue( px, 64*(b/64))
repaint( pic2 )
Thanks,
Joe
You didn't specify the python version. But I'd guess you're using 2.x
(as opposed to 3.x), where dividing integers gives an integer by
default. To quickly check, try
print 25/9
and if you get 2, you'll see what I mean. When you then multiply 2 by
9, you get 18.
DaveA
_______________________________________________
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor