Turtle Graphics: The Logo language made the concept of turtle graphics famous. Imagine a mechanical turtle that walks around the room under the control of a C program. The turtle holds a pen in one of two positions, up or down. While the pen is down, the turtle traces out shapes as it moves; while the pen is up, the turtle moves about freely without writing anything. In this problem, youll simulate the operation of the turtle and create a computerized sketchpad as well.
Use a 200-by-200 array floor which is initialized to zeros. Keep track of the current turtle position at all times and whether the pen is currently up or down. Assume that the turtle always starts at position 0, 0 of the floor with its pen up. The set of turtle commands your program must process are shown in Figure below.
Suppose that the turtle is somewhere near the center of the floor. The following program would draw and print a 12-by-12 square:
Command and Meaning
Example Run:
Enter Commands (9 to end input): 2
Enter Commands (9 to end input): 5, 12
Enter Commands (9 to end input): 3
Enter Commands (9 to end input): 3
Enter Commands (9 to end input): 5, 12
Enter Commands (9 to end input): 3
Enter Commands (9 to end input): 3
Enter Commands (9 to end input): 5, 12
Enter Commands (9 to end input): 3
Enter Commands (9 to end input): 3
Enter Commands (9 to end input): 5, 12
Enter Commands (9 to end input): 1
Enter Commands (9 to end input): 6
Enter Commands (9 to end input): 9
Sample output: see image.
As the turtle moves with the pen down, set the appropriate elements of array floor to 1s. When the 6 command (print) is given, wherever theres a 1 in the array, display an asterisk, or some other character you choose. Wherever theres a zero, display a blank. You may also define an additional array containing the commands that you want to use.
a) Write a program to draw IMU (filling the entire grid) using all of the above commands.
b) Write a test program that uses the required commands [i.e., Using turtle commands from above] to print 5 characters SPACE (You may have to adjust the array floor to a larger size and add few more commands to the turtle program).
Note: If turtle is asked to go beyond the edge, it should turn around and keep counting.