We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexSuggestions & BugsSoftware,  Documentation,  Website Suggestions › Parameter Order in PImage set method
Page Index Toggle Pages: 1
Parameter Order in PImage set method (Read 1493 times)
Parameter Order in PImage set method
Oct 18th, 2009, 12:47pm
 
Greetings,

During a class discussion, my students and I noticed something curious.  Parameters for the PImage set method can be passed in any order and it will be accepted by Processing:

PImage theImage = loadImage( "homer.jpg" );
color theColor = color( 255, 255, 255 );

// Pass parameters in different orders
theImage.set( 0, 0, theColor );
theImage.set( theColor, 0, 0 );

Only the "proper" order will do what you want  and change the color of the pixel to white.

It appears that this is caused by the fact that there is an implicit cast from color to int.

This caused some considerable problems and was somewhat hard to explain to beginning students even after realizing what was wrong.

Thank you,

Jeff
Re: Parameter Order in PImage set method
Reply #1 - Oct 19th, 2009, 2:43am
 
Jeffrey Edgington wrote on Oct 18th, 2009, 12:47pm:
there is an implicit cast from color to int.

It is not a cast, 'color' pseudo type is actually a good old int.
Somehow, the problem can occur with any function with parameters of same type, for example get().
It is a lesson in reading carefully the reference manual...  Tongue
Re: Parameter Order in PImage set method
Reply #2 - Oct 19th, 2009, 10:09am
 
There were questionable design decisions made with naming the color datatype and the color() function, but there's no way to fix the problem you introduce. It's all ints and the compiler will parse them as such. There are many cases of functions that have parameters of the same datatype and it's not possible to receive an error. The order is always important.
Page Index Toggle Pages: 1