Python

(파이썬) 자유 낙하 운동 궤적 그리기

고니자니 2022. 10. 10. 08:50
반응형

물체가 높은 곳에서 아래로 떨어질 때는 중력으로 인해 약 9.8m/초씩 속도가 증가하게 됩니다.

다음 코드는 시간의 변화에 따른 거리의 변동을 파이썬의 터블 그래픽으로 표현한 것입니다.

 

import turtle as t
t.shape("circle")

def draw_pos(x, y):
    t.clear()
    t.hideturtle() 
    t.setpos(x,y)
    t.showturtle()   
    t.stamp()

    hl = -(t.window_height() / 2)

    tm = 0
    while True:
        d = (9.8 * tm**2) / 2
        ny = y - int(d)
        if ny > hl:
            t.goto(x, ny)
            t.stamp()
            tm = tm + 0.5
        else:
            break

t.setup(400, 800)
#t.shape("circle")
t.shapesize(0.5, 0.5, 0)
t.penup()
t.hideturtle()       
s = t.Screen()
s.onscreenclick(draw_pos)
s.listen()

(파이썬) 자유 낙하 운동 궤적 그리기

728x90
반응형