(Turtle Graphics) The Logo language made famous the concept of turtle graphics. Imagine a…
(Turtle Graphics) The Logo language made famous the concept of turtle graphics. Imagine a mechanical turtle that walks around the room under the control of a 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 without writing anything. In this problem, you will simulate the operation of the turtle and create a computerized sketchpad.
Use a 20-by-20 array floor, which is initialized to zeros. Read commands from an array that contains them. At all times, keep track of the current position of the turtle and whether the pen is 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 as follows:
Suppose that the turtle is somewhere near the center of the floor. The following “program” would draw and print a 12-by-12 square, leaving the pen in the up position:
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 there is a 1 in the array, display an asterisk or another character. Wherever there is a zero, display a blank. Write a program to implement the turtle graphics capabilities we have discussed. Write several turtle graphics programs to draw interesting shapes. Add commands to increase the power of your turtle graphics language.