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.

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter5: Control Structures Ii (repetition)
Section: Chapter Questions
Problem 27PE
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
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
Microsoft Visual C#
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,