I need to model a spring in Python for one of my classes at the university and it doesn't really work. I've the second order differential equation and I translated it in 2 first order ones to have a system. Can someone look my code and give me an idea about what could I do? For me, the equations are good, I just don't know how to draw it...
from math import pi
from time import sleep
from turtle import *
k=1
m=1
def main():
L = 5
total_time = 0
vo = 0 #Vitesse angulaire initial (rad/s)
time_step = 0.05
while total_time < 100:
total_time += time_step
vo += (-k/m) * L * time_step
L += vo * time_step
if draw(L): break
sleep(time_step)
def init():
setup()
mode('logo')
radians()
speed(0)
tracer(False)
hideturtle()
def draw(L):
if speed() != 0: return True
clear()
pendown()
setheading(L)
penup()
pensize(5)
pencolor('red')
dot(L * 10)
home
update()
if __name__ == '__main__':
init()
main()