[英]How can I draw a projectile arc on turtle graphics?
我需要幫助來學習如何在海龜圖形中繪制弧線。 我更喜歡一組簡單的代碼,我可以很容易地將它們合並到我預先存在的代碼中。
我嘗試按照在線說明制作弧線,但它不是射彈,更像是笑臉弧線。
此代碼跟蹤兩個變量,一個稱為x_velocity
,另一個稱為y_velocity
。 這些變量分別表示彈丸在 x 和 y 方向上移動的速度。 然后循環幾次,以這些速度移動海龜,然后將重力應用於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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.