[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

LOGO-L> Recursive ChessBoard in MSWLogo



Hi,

Blaho and Kalas, in their Learning by Developing, Logotron (1998), show (p.106) how to draw a chessboard in SuperLogo, using, what they call, polygon lists.

It can be programmed in several other ways. One method is to use recursion. Recursively it can be drawn in any favor of Logo, I think.

The main problem is how to do properly the coloring: in my following solution it's done in procedure FILL_IT while drawing the squares.

To run it say: DRAW 160 4:

to draw :size :level ; Recursive Chessboard
if :level<1[stop]
repeat 4[shape]
fill_it
end

to shape
draw :size/2 :level-1
fd :size rt 90
end

to fill_it
setfc ifelse 0=remainder heading 180[4][6]
pu rt 45 fd :size/2 pd fill
pu bk :size/2 lt 45 pd
end
You might have noted, that the 160 (in DRAW 160 4) is the side of the board, so it's advisable to have it a multiple of 8 (for 8 equal squares), if you want to do a precise job.

If you compare the code with that of CARPET (I posted here recently), you might discover more that one line of resemblance. That's, because most recursive graphics have behind them the very same logic, and hence - similar patterns.

Regards,

Yehuda

    _/    _/     _/ _/_/_/_/_/ _/_/_/_/
   _/   _/     _/_/    _/          _/
  _/_/_/     _/  _/   _/        _/
 _/   _/   _/_/_/_/  _/      _/
_/     _/_/      _/ _/     _/_/_/_/

http://www.geocities.com/CollegePark/lab/2276/
e-mail: yehuka@softhome.net
 

GIF image



Global SchoolNet Foundation - Linking Kids Around the World!
Copyright GSN - All Rights Reserved - Comments & Questions
Visit GSN's Global Schoolhouse for more exciting learning resources!
Search our Site - Home