Re: making a checkerboard array? [message #55985 is a reply to message #55935] |
Wed, 26 September 2007 10:27   |
JD Smith
Messages: 850 Registered: December 1999
|
Senior Member |
|
|
On Tue, 25 Sep 2007 15:52:33 -0600, David Fanning wrote:
> JD Smith writes:
>
>>> I'm trying to make a checkerboard mask for an array, but I'm missing
>>> something that is likely to be obvious to the IDL array masters.
>>
>> l=lindgen(nx,ny)
>> l=(l mod (xside*2) lt xside) XOR (l/nx mod (yside*2) ge yside)
>
> Well, uh, it's not obvious to me. :-(
Well, l mod (xside*2) produces a horizontal ramp from 0... xside*2,
repeating over and over, the same for each row (as long as the array
width is an even multiple of xside). Comparing this ramp to xside,
ala (ramp lt xside) produces alternating vertical bars of width xside.
Similarly for l/nx (the row number), producing alternating horizontal
bars of height yside. Put them on top of each other and you have a
lovely quilt pattern. But we don't want a quilt, we want a
checkerboard, i.e. we want only those spots where the two bar patterns
don't overlap, hence the exclusive or (XOR).
In case that wasn't clear, here it is dfanning style ;)
theRamp = LINDGEN( theNumberofXPixels , theNumberofYPixels )
theCheckerBoardHorizontalPeriod = 2 * theCheckWidth
theHorizontalRamp = theRamp MOD theCheckerBoardHorizontalPeriod
theHorizontalBands = theHorizontalRamp LT theCheckWidth
theRowNumbers = theRamp/theNumberofXPixels
theCheckerBoardVerticalPeriod = 2 * theCheckHeight
theVerticalRamp = theRowNumbers MOD theCheckerBoardVerticalPeriod
theVerticalBands = theVerticalRamp GE theCheckHeight
theCheckerBoard = theHorizontalBands XOR theVerticalBands
JD
|
|
|