Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a JavaScript program which will simulate turtle graphics. You will use two dimensional array to represent a floor of 20 x 20. The commands

Write a JavaScript program which will simulate turtle graphics. You will use two dimensional array to represent a floor of 20 x 20. The commands that you can give to the turtle is

image text in transcribed

Your program will list the commands and their meaning. There are one textbox for user to enter command number, two buttons: one for send command, the other one for process the commands sent. The following shows the screen shot

image text in transcribed

Assume the turtle will starts from (0, 0). When pen down, it will start to draw. You can draw any character of your choice. Here we will use *. When turtle hit the wall, it will wrap around. For example. If it hit floor[3][19] and intend to go to floor[3][20]. Because there are 20 in y so it will become floor[3][0]. The following commands 2, 5, 10, 3, 5, 10, 3, 5, 10, 3, 5, 10, 1, 6, 9 (note each time you enter a number, you press the Submit Command. After you enter 9, you will press Process Commands. The output of the above sequence will generate the following on your web page.

image text in transcribed

The following sequence

2, 5, 7, 3, 5, 7, 3, 5, 7, 3, 5, 7, 1,// draw 1st square

3, 5, 4, 3, 5, 4, 4, // reposition turtle

2, 5, 7, 3, 5, 7, 3, 5, 7, 3, 5, 7, 1, // draw 2nd square

6, 9 ]; // end

Will display two squares as the following

image text in transcribed

meaning Pen up Pen down Command Turn right 4 Turn left Two commands means move forward 12 spaces. You can specify how many steps by change 12 to that value. For example 5, 3 means you enter 5 press the 5, 12 6 Print the 20 x 20 array End of data

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Seven Databases In Seven Weeks A Guide To Modern Databases And The NoSQL Movement

Authors: Luc Perkins, Eric Redmond, Jim Wilson

2nd Edition

1680502530, 978-1680502534

More Books

Students also viewed these Databases questions

Question

Provide the specific components of a facility WAP.

Answered: 1 week ago