1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
|
"""le but est de remplir une grille de 20 sur 20 par des points rouges
Inspiré de
https://www.youtube.com/watch?v=rbFws9XGu0s&list=PLDtut0doG41ZH8owcjxvSYgNq2vkw92tH&index=11
video à 8 mn 30"""
from numpy import *
import matplotlib.pyplot as plt
from matplotlib.animation import FuncAnimation
z=0
def animate(i):
global z
balle.set_data(x[:z], y[:z])
z+=1
return balle,
############################
x=[]
y=[]
for s in range(1, 21):
for t in range(1, 21):
x.append(s)
y.append(t)
a=linspace(1,20,20,dtype=int)
b=linspace(1,20,20,dtype=int)
a,b= meshgrid(a, b)
fig, ax = plt.subplots()
xmax = 21
xmin = 0
ymax = 21
ymin = 0
ax.set_xlim(xmin, xmax)
ax.set_ylim(ymin, ymax)
ax.set_aspect('equal')
scat=plt.scatter([a],[b],marker='.',c='white',edgecolors='black',s=300)
balle,=ax.plot([],[],'ro',ms=7)
sc =FuncAnimation(fig, animate, frames=linspace(0,399,400,dtype=int),interval=10, blit=True, repeat=False)
plt.show() |
Partager