# -*- coding: utf-8 -*-
"""
Created on Wed Apr  1 11:12:14 2026

@author: François Coulombeau
"""
import numpy as np
import matplotlib.pyplot as plt

thet = np.pi-0.001
thetp = 0
Thet = [thet]
ThetP = [thetp]

dt = 1/250
Dt = 1/25
n = int(Dt//dt)
g = 10
l = 0.3
alpha = 0.1
N = 2500
k = 0
while k<N:
    thetp = thetp + dt*((-g/l)*np.sin(thet)-alpha*thetp)
    thet = thet + dt*thetp
    Thet.append(thet)
    ThetP.append(thetp)
    k += 1

tt = Thet[0]
X = [0, l*np.sin(tt)]
Y = [0, -l*np.cos(tt)]

plt.axis([-l,l,-l,l])
plt.axis("scaled")
fig = plt.plot(X,Y,"k")[0]
for i in range(n,len(Thet),n):
    tt = Thet[i]
    X = [0, l*np.sin(tt)]
    Y = [0, -l*np.cos(tt)]
    fig.set_data(X,Y)
    plt.pause(Dt)
plt.figure()
plt.plot(Thet,ThetP)