Q2. Let’s have some fun! You can copy and paste my code in blue. Turtle graphics is a classic teaching tool in computer science, originally invented in the 1960s and reimplemented over and over again in different programming languages. Let’s first install and load that package. library(TurtleGraphics) Here’s the idea. You have a turtle, and she lives in a nice warm terrarium: turtle_init() Your job is to give her instructions, to program her to undertake certain actions. So for example, you can use the turtle_forward(distance=) command to get her to walk forwards, the turtle_left(angel=) command to get her to rotate to the left, turtle_backward(distance=) command to get her to walk backwards, and turtle_right(angel=) command to get her to walk to the right. For example, if I used this command my turtle would walk forward 10 steps and leave a trail behind her showing the path she took. turtle_forward(distance = 10) That seems simple enough, but what if I want my turtle to draw a more complicated shape? Let’s say I want her to draw a hexagon. There are six sides to the hexagon, so the most natural way to write code for this is to write a for loop that loops over the sides! At each iteration within the loop, I’ll have the turtle walk fowards, and then turn 60 degrees to the left. Here’s what happens: turtle_init() for(side in 1:6) { turtle_forward(distance = 10) turtle_left(angle = 60) } 1) Use TurtleGraphics to draw a square rather than a hexagon. 2) Use TurtleGraphics to draw a triangle.
Q2. Let’s have some fun! You can copy and paste my code in blue. Turtle graphics is a classic teaching tool in computer science, originally invented in the 1960s and reimplemented over and over again in different programming languages. Let’s first install and load that package. library(TurtleGraphics) Here’s the idea. You have a turtle, and she lives in a nice warm terrarium: turtle_init() Your job is to give her instructions, to program her to undertake certain actions. So for example, you can use the turtle_forward(distance=) command to get her to walk forwards, the turtle_left(angel=) command to get her to rotate to the left, turtle_backward(distance=) command to get her to walk backwards, and turtle_right(angel=) command to get her to walk to the right. For example, if I used this command my turtle would walk forward 10 steps and leave a trail behind her showing the path she took. turtle_forward(distance = 10) That seems simple enough, but what if I want my turtle to draw a more complicated shape? Let’s say I want her to draw a hexagon. There are six sides to the hexagon, so the most natural way to write code for this is to write a for loop that loops over the sides! At each iteration within the loop, I’ll have the turtle walk fowards, and then turn 60 degrees to the left. Here’s what happens: turtle_init() for(side in 1:6) { turtle_forward(distance = 10) turtle_left(angle = 60) } 1) Use TurtleGraphics to draw a square rather than a hexagon. 2) Use TurtleGraphics to draw a triangle.
Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
Related questions
Question
Q2. Let’s have some fun! You can copy and paste my code in blue.
Turtle graphics is a classic teaching tool in computer science, originally invented in the 1960s and
reimplemented over and over again in different programming languages. Let’s first install and load that
package.
library(TurtleGraphics)
Here’s the idea. You have a turtle, and she lives in a nice warm terrarium:
turtle_init()
Your job is to give her instructions, to program her to undertake certain actions. So for example, you can
use the turtle_forward(distance=) command to get her to walk forwards, the turtle_left(angel=)
command to get her to rotate to the left, turtle_backward(distance=) command to get her to walk
backwards, and turtle_right(angel=) command to get her to walk to the right. For example, if I used this
command my turtle would walk forward 10 steps and leave a trail behind her showing the path she
took.
turtle_forward(distance = 10)
That seems simple enough, but what if I want my turtle to draw a more complicated shape? Let’s say I
want her to draw a hexagon. There are six sides to the hexagon, so the most natural way to write code
for this is to write a for loop that loops over the sides! At each iteration within the loop, I’ll have the
turtle walk fowards, and then turn 60 degrees to the left. Here’s what happens:
turtle_init()
for(side in 1:6) {
turtle_forward(distance = 10)
turtle_left(angle = 60)
}
1) Use TurtleGraphics to draw a square rather than a hexagon.
2) Use TurtleGraphics to draw a triangle.
Turtle graphics is a classic teaching tool in computer science, originally invented in the 1960s and
reimplemented over and over again in different programming languages. Let’s first install and load that
package.
library(TurtleGraphics)
Here’s the idea. You have a turtle, and she lives in a nice warm terrarium:
turtle_init()
Your job is to give her instructions, to program her to undertake certain actions. So for example, you can
use the turtle_forward(distance=) command to get her to walk forwards, the turtle_left(angel=)
command to get her to rotate to the left, turtle_backward(distance=) command to get her to walk
backwards, and turtle_right(angel=) command to get her to walk to the right. For example, if I used this
command my turtle would walk forward 10 steps and leave a trail behind her showing the path she
took.
turtle_forward(distance = 10)
That seems simple enough, but what if I want my turtle to draw a more complicated shape? Let’s say I
want her to draw a hexagon. There are six sides to the hexagon, so the most natural way to write code
for this is to write a for loop that loops over the sides! At each iteration within the loop, I’ll have the
turtle walk fowards, and then turn 60 degrees to the left. Here’s what happens:
turtle_init()
for(side in 1:6) {
turtle_forward(distance = 10)
turtle_left(angle = 60)
}
1) Use TurtleGraphics to draw a square rather than a hexagon.
2) Use TurtleGraphics to draw a triangle.
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by step
Solved in 6 steps with 4 images
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Recommended textbooks for you
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education