0
i need help with question.....Turtle graphics with 20by20 array floor with a set of commands....check comment for full question
16 ответов
0
imagine a mechanical turtle that walks around the room under the control of a java application..the turtle holds a pen in one if two positions, up or down. while the pen is down, the turtle traces out shapes as it moves and while its up, the turtle moves around freely without writing anything.
use a 20 by 20 array that's initialized to zeros.. read commands from an array that contains them.
Commands. Meaning
1. pen up
2. pen down
3 turn right
4. turn left
5,10. move forward 10 spaces
6. display the 20 by 20
array
9. end of data(sentinel)
the following program would draw and display a 12 by 12 square.
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 array to 1s.. When the 6 command(display array) is given, wherever there's a 1 in the array, display an asterisk.. Wherever there's a 0, display a blank.
please i hope you help me
0
Illegal Please see the attached code. Also, bear in mind that python has a turtle module that you could use instead.
https://code.sololearn.com/cSJgn9q6dYTd/?ref=app
0
thanks a lot........though its kinda hard to understand......but still, i appreciate
0
Yeah. It's not as succinct as it could be. There are things that can be done to reduce it, like putting the movement into a single function, but I didn't plan it so compounded my inefficiency as I worked.
Hopefully it gives you an idea so that you can make it in a way that makes sense to you.
Best of luck.
p.s. look at it on a PC instead of phone ( more screen real estate).
0
okay
0
benjamin
please can you comment the key area from the if(command == 3)....
please i dont understand from there
0
I've added some comments that I hope you will find useful. Let me know what you think. Cheers.
0
thanks a lot bro......it helps a lot.......i really appreciate.
if i meet any problem, i will get back to you
0
also, i wanted to know.......storing your commands in an array......is that a one dimension or multidimensional array in python
0
No problem at all.
It's actually a list. Arrays store values of a single data type and, in Python, the array module must be imported to use it. Besides, it only suppprts primitive data types of a fixed-size, so wouldn't include a list.
The commands are stored in a list. This allows values of different types to be stored and is mutable. Therefore you have integers and lists together in one data structure and can add as many commands as you need.
0
list.....as in array list😧😧
0
No, it's not the same thing. Perhaps you should have a read of the docs on lists and look at the equivalent for Java to learn about the differences between them. Best of luck and keep at it. It falls into place one piece at a time.
0
hello....long time👋👋.....i'm having a little problem.
turtlex and turtley, what is their function in that program
0
They simulate the horizontal and vertical movement. In reality, Y refers to the index of the main list whereas X refers to the index of the nested list. On a smaller scale. If we had a list of lists of zeros (called grid) like:
[ [0, 0, 0] ,
[0, 0, 0] ,
[0, 0, 0] ]
If I set the variables:
turtleX = 2
turtleY = 1
Then update the contents of the list:
grid [turtleY][turtleX] = 1
then we end up with:
[ [0, 0, 0] ,
[0, 0, 1] ,
[0, 0, 0] ]
0
okay
also, i dont understand the loop condition for line 52 & 57......please explain
0
it's handling a vertical movement upwards. if there is enough space to move up the grid for the whole move (e.g. [5,12] is 12 moves), then it will do so using the loop at line 52. If the move will take the turtle beyond the grid, then it only moves to the edge using the loop at line 57.