The LOGO Programming language is fun to learn. It was first designed for teaching children to program as their first programming language. The Turtle Graphics is easy to understand. We control it to draw lines in different colour by using different commands such as FD (FORWARD), BK (BACKWARD) etc.
The PHP Online LOGO Interpreter can be found [here]. In this page, you can copy&paste the LOGO program and execute it in server side. Meantime, it is possible to convert the LOGO program into a Win32 PE format (*.exe executable).
Today, I am going to show you how to draw a chess board in LOGO programming language (previously, this can be done in here, here and here).
To draw a filled (solid) square, you can use recursion:
A recursion is a function calling itself. In Logo, we can define a procedure, asking the turtle to draw something, then ask the turtle to repeat itself but with slightly different parameters, until a set of conditions are met.
For example, the following procedure can be used to draw a filled rectangle.
TO FK :B HT # hide the turtle IF :B>15 [STOP] REPEAT 4 [FD :B RT 90] FK :B+1 # draw a bigger square to fill END
We can use FK 15 to draw a empty square as well. Now we can create a board like this:
The FK 15 draws a empty square. By such, we can draw the interleaving squares.
TO QP :Y IF :Y>4 [STOP] REPEAT 4 [FK 15 FD 15 FK 1 FD 15] RT 90 FD 30 RT 90 REPEAT 4 [FK 15 FD 15 FK 1 FD 15] RT 180 QP :Y+1 END
Feed the QP with parameter 1 to start drawing. You could use this PHP-LOGO Interpreter to verify the LOGO program as stated above.
See also the Python code for drawing a chess board based on turtle package/library: Teaching Kids Programming – How to Draw a Chess Board using Python and Turtle Graphics?
–EOF (The Ultimate Computing & Technology Blog) —
loading...
Last Post: Coding Exercise – Timus Online Judge – 1820. Ural Steaks, C/C++ solution
Next Post: Coding Exercise - C++ - Codeforces - B. The least round way - Dynamic Programming