【问题标题】:How can I draw a projectile arc on turtle graphics?如何在海龟图形上绘制射弹弧线?
【发布时间】:2022-11-21 11:31:54
【问题描述】:

我需要帮助来学习如何在海龟图形中绘制弧线。我更喜欢一组简单的代码,我可以很容易地将它们合并到我预先存在的代码中。

我尝试按照在线说明制作弧线,但它不是射弹,更像是笑脸弧线。

【问题讨论】:

    标签: python turtle-graphics python-turtle python-3.9


    【解决方案1】:

    此代码跟踪两个变量,一个称为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
    

    【讨论】:

    • 感谢您的帮助,但对于我的代码,用户选择角度(度)和拱形速度。
    猜你喜欢
    • 2014-06-16
    • 2016-01-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-03-16
    • 2014-12-14
    • 1970-01-01
    相关资源
    最近更新 更多