making a checkerboard array? [message #55935] |
Tue, 25 September 2007 09:27  |
Mike[2]
Messages: 99 Registered: December 2005
|
Member |
|
|
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. The
following code makes a pattern like this (use a fixed width font):
+++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++
00000+++++00000+++++00000+++++
00000+++++00000+++++00000+++++
00000+++++00000+++++00000+++++
++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++
00000+++++00000+++++00000+++++
00000+++++00000+++++00000+++++
00000+++++00000+++++00000+++++
++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++
00000+++++00000+++++00000+++++
00000+++++00000+++++00000+++++
00000+++++00000+++++00000+++++
Can anyone help me fill in the missing rectangles like this?
+++++00000+++++00000+++++00000
+++++00000+++++00000+++++00000
+++++00000+++++00000+++++00000
00000+++++00000+++++00000+++++
00000+++++00000+++++00000+++++
00000+++++00000+++++00000+++++
+++++00000+++++00000+++++00000
+++++00000+++++00000+++++00000
+++++00000+++++00000+++++00000
00000+++++00000+++++00000+++++
00000+++++00000+++++00000+++++
00000+++++00000+++++00000+++++
+++++00000+++++00000+++++00000
+++++00000+++++00000+++++00000
+++++00000+++++00000+++++00000
00000+++++00000+++++00000+++++
00000+++++00000+++++00000+++++
00000+++++00000+++++00000+++++
Nx=300
Ny=200
Nrects = 10
Xside = Nx/Nrects
Yside = Ny/Nrects
xs = [replicate(1,Xside), replicate(0,Xside)]
while n_elements(xs) lt Nx do xs = [xs, [replicate(1,Xside),
replicate(0,Xside)]]
xs = xs[0:Nx-1]
ys = [replicate(1,Yside), replicate(0,Yside)]
while n_elements(ys) lt Ny do ys = [ys, [replicate(1,Yside),
replicate(0,Yside)]]
ys = ys[0:Ny-1]
window, xsize=Nx, ysize=Ny
tvscl, xs # ys
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Re: making a checkerboard array? [message #56033 is a reply to message #55935] |
Tue, 25 September 2007 09:56   |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
Mike 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. The
> following code makes a pattern like this (use a fixed width font):
Here is my implementation:
Function Checkerboard, xsize, ysize, white, black
IF N_Elements(xsize) EQ 0 THEN xsize = 512
IF N_Elements(ysize) EQ 0 THEN ysize = 512
IF N_Elements(white) EQ 0 THEN white = 255
IF N_Elements(black) EQ 0 THEN black = 0
IF xsize MOD 2 NE 0 THEN $
Message, 'The X size must be an even number.'
IF ysize MOD 2 NE 0 THEN $
Message, 'The Y size must be an even number.'
horizontalBoard = FltArr(xsize, ysize)
verticalboard = FltArr(xsize, ysize)
xhalfSize = xsize / 2
x = IndGen(xhalfSize) * 2
yhalfSize = ysize / 2
y = IndGen(yhalfsize) * 2
horizontalBoard[x,*] = 1
verticalBoard[*,y] = 1
verticalBoard = Temporary(verticalBoard) + horizontalBoard
verticalBoard[Where(verticalBoard EQ 2)] = 0
board = FltArr(xsize, ysize) + white
board[Where(verticalBoard GT 0)] = black
RETURN, board
END
Are you working through Gonzales and Woods? My 3rd Edition just
arrived yesterday! :-)
Cheers,
David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
|
|
|
Re: making a checkerboard array? [message #56071 is a reply to message #55993] |
Thu, 27 September 2007 07:54  |
edward.s.meinel@aero.
Messages: 52 Registered: February 2005
|
Member |
|
|
On Sep 26, 12:44 pm, "R.G. Stockwell" <noem...@please.com> wrote:
> "Bruce Bowler" <bbow...@bigelow.org> wrote in message
>
> news:pan.2007.09.26.15.19.33@bigelow.org...
>
>>> http://www.nerdtests.com/ft_nq.php;-)
>
>> Arghhhhhh 91. I didn't think I was *that* nerdy :-)
>
> OHOH!
>
> {takes test results, prints them to printer, and burns them! Pleasantly
> dreams of
> scoring only 91}
99! No, that doesn't mean 'factorial'... Oooo, Agent 99, yowza!
Bruce, why are you so surprised? You're posting on comp.lang.idl-
pvwave, for crying out loud!
Ed "supreme nerd god" Meinel
|
|
|