Da es uU lange dauert, ALLE Polygone neu zu zeichnen, möchte ich nur das jeweils das letzte neu zeichnen. Die Polygone aus den vorherigen fraems sollen aber zu sehen bleiben.
blit=True/False löst das Problem nicht, weil in der init-Function noch keine Polygone vorhanden sind.
Code: Alles auswählen
import matplotlib.patches as patches
from matplotlib import animation
import random
print random.randint(0,10)
def init():
xlim(-10.,110.)
ylim(-10.,110.)
return tuple([])
def newFrame(i):
obstacle = []
for ip in range(i):
obstacle.append(gca().add_patch(patches.Polygon(poly[ip], color="grey", edgecolor=None)))
return tuple(obstacle)
# main program
poly = []
for i in range(1000):
poly.append([ [random.randint(0, 100),random.randint(0, 100)],\
[random.randint(0,100),random.randint(0,100)], \
[random.randint(0,100),random.randint(0,100)] ])
fig = figure(1)
ani = animation.FuncAnimation(fig, newFrame, init_func=init, blit=True)
show()
sys.exit