|
Please help with Java Coding*****************The Logo language, which is popular among young computer users made the concept of Turtle graphics famous, Imagine a mechanical turtle that walks around the room under the control of a JavaScript program. The turtle holds the pen in one of two positions. Up or down. When the pen is down, the turtle traces out shapes as it moves. When the pen is up, the turtle moves about freely without writing anything. In this problem you will simulate the operation of the turtle and create a computerized sketchpad as well.
Use a 20 by 20 array floor that is initialized to Zeros. Read commands from an array that contains them. Assume the turtle always starts at position (0,0) of the floor with its pen up. The commands your script must process are as follows:
Command Meaning
1 Pen up
2 Pen down
3 Turn right
4 Turn left
5, 10 Move forward 10 spaces or a number other than ten
6 Print the 20 by 20 array
9 End of data (sentinel)
Suppose that the turtle is somewhere near the center of the floor. The following program would draw and print a 12 by 12 square and then leave the pen in the up position:
2
5, 12
3
5, 12
3
5, 12
3
5, 12
1
6
9
As the turtle moves with the pen down set the appropriate elements of the array floor to 1s. When the 6 (print) command is given, display an asterisk wherever there is a 1 in the array. Wherever there is a zero display a blank. Write a script to implement the turtle graphics capabilities discussed here.
|
|
|
|
|
|
|
|