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

  • 1 - Pen up
  • 2 - Pen Down
  • 3 - Turn Right by 45 degrees
  • 4 - Turn Left by 45 degrees
  • 5, X - Move forward X spaces
  • 6 - Print 200-by-200 array
  • 7 - Turn Right by 180 degrees
  • 9 - End of data (sentinel)

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.

Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.