I am not certain where to put this anecdote- but perhaps it might be of interest either here or if promoted in the general forum.
This is the story of how I learned to use Pixel Math. I presented this story during the recent AIC conference in San Jose.
When learning this seemingly complex tool- I decided to make a problem for myself and proceed to solve it. The problem I made was to use PixelMath to create
a checkerboard (chess board) pattern of pixels. Going through this exercise taught me how to define variables, use functions and understand the meaning of accessing
a pixel's value or position in the image array.
To solve the problem I knew I had to figure out a way to make the values of a pixel oscillate between 0 and 1 based on the position of the pixels as PixelMath rasters the image.
I recognized that the even or oddness of the x and y positions would give me a hook. This instantly triggered a memory that computer programmers use the modulus operator (%)
to check for the even or oddness of numbers... and that was my starting point. The Modulus operator returns the value that is the integer remainder of the division of two numbers.
In the special case of any x%2 the remainder is either 0 or 1. So not only can I use the returned value as the value I assign to the pixel... it is also in some sense a boolean result!
That is when I settled on the expression:
x=x();
y=y();
iif(y%2, ~(x%2), x%2)
By checking whether the row defined by y is even or odd- I determine whether the row starts with a black pixel or a white pixel (by inverting the result).
I personally thought this was clever and it was a happy day for me!
However... I presented this last weekend (September 30th 2017) at the AIC conference and a gentleman in the audience pointed out I could create an even simpler expression, namely:
x=x();
y=y();
(x+y)%2
In this sense the even or oddness of y is being used in the addition to change the even or oddness of the expression yielding an identical result.
There is always someone more clever out there!
Just for completeness I queried Carlos M. and ask what expression he might come up with... his solution was
x=x();
y=y();
i=-1;
i^(x+y)
However, I found his solution too complex for my tastes.
-Adam Block