简体   繁体   中英

How can I draw a projectile arc on turtle graphics?

I need help with learning how to draw a arc in turtle graphics. I would prefer a simple set of code that I can easily incorporate into my pre-existing code.

I've tried to make an arc following online instructions but its not projectile, its more like a smiley face arc would be.

This code keeps track of two variables, one called x_velocity , and the other called y_velocity . These variables represent the speed that the projectile is moving in x and y directions respectively. It then loops through a couple times, moving the turtle at those velocities and then applying gravity to the y_velocity .

import turtle
t = turtle.Turtle()
t.speed(3) # 1:slowest, 3:slow, 5:normal, 10:fast, 0:fastest

x_velocity = 4
y_velocity = 20

for i in range(50):
  # apply velocity to the turtle, move it
  t.goto(t.xcor() + x_velocity, t.ycor() + y_velocity)
  # apply gravity to the projectile
  y_velocity -= 1

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM