Vertically Centered Triangle And now, modify the above program to center the triangle vertically as well as horizon- tally, updating the dot location too. Your output should like as follows, Here is my answer: # Import the turtle module import turtle # Create a turtle object t = turtle.Turtle() # Set the speed and the pen size t.speed(0) t.pensize(3) # Define a function to draw a triangle with a dot in the center def draw_triangle(): # Draw a triangle for i in range(3): t.forward(100) t.left(120) # Move to the center t.penup() t.forward(50) t.left(60) t.forward(28.87) # This is the height of an equilateral triangle divided by 2 t.right(90) # Draw a dot t.dot(10) # Move back to the corner t.left(90) t.forward(28.87) t.right(60) t.forward(50) t.left(120) t.pendown() # Move to the center of the screen t.penup() t.goto(0, 0) t.pendown() # Draw the triangle draw_triangle() # Hide the turtle t.hideturtle() # Exit on click turtle.exitonclick()     My question here: Your First Animation Now that you’ve had a chance to experiment with animations, its your turn to write one. Create an animation that is based upon your code the question “Vertically Centered Triangle”. This animation should feature the same triangle. However, the dot should bounce up and down (so update the y coordinate) inside of the triangle. When it reaches the edges of the triangle, its velocity should be reversed so that it always remains inside of the shape.

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
icon
Related questions
Question

Vertically Centered Triangle
And now, modify the above program to center the triangle vertically as well as horizon-
tally, updating the dot location too. Your output should like as follows,

Here is my answer:

# Import the turtle module
import turtle

# Create a turtle object
t = turtle.Turtle()

# Set the speed and the pen size
t.speed(0)
t.pensize(3)

# Define a function to draw a triangle with a dot in the center
def draw_triangle():
# Draw a triangle
for i in range(3):
t.forward(100)
t.left(120)

# Move to the center
t.penup()
t.forward(50)
t.left(60)
t.forward(28.87) # This is the height of an equilateral triangle divided by 2
t.right(90)

# Draw a dot
t.dot(10)

# Move back to the corner
t.left(90)
t.forward(28.87)
t.right(60)
t.forward(50)
t.left(120)
t.pendown()

# Move to the center of the screen
t.penup()
t.goto(0, 0)
t.pendown()

# Draw the triangle
draw_triangle()

# Hide the turtle
t.hideturtle()

# Exit on click
turtle.exitonclick()

 

 

My question here:

Your First Animation
Now that you’ve had a chance to experiment with animations, its your turn to write
one. Create an animation that is based upon your code the question “Vertically Centered
Triangle”. This animation should feature the same triangle. However, the dot should
bounce up and down (so update the y coordinate) inside of the triangle. When it reaches
the edges of the triangle, its velocity should be reversed so that it always remains inside
of the shape.

Expert Solution
steps

Step by step

Solved in 4 steps with 1 images

Blurred answer
Knowledge Booster
Random Class and its operations
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.
Similar questions
Recommended textbooks for you
Database System Concepts
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)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education