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.")
|
|
|