Fruitydelicious — Animations (11.02.2023)
plt.show() This animation showcases a variety of fruits growing and changing sizes.
def animate(i): global vx, vy # Update fruit position x, y = fruit.get_data() x += vx y += vy
# Initialize the plot ax.set_xlim(0, 10) ax.set_ylim(0, 10) Fruitydelicious animations (11.02.2023)
ani = animation.FuncAnimation(fig, animate, frames=200, blit=True, interval=20)
def animate(i): ax.clear() ax.set_xlim(0, 10) ax.set_ylim(0, 10) for fruit in fruits: fruit['size'] += 0.1 # Grow the fruits ax.add_patch(plt.Circle((fruit['x'], fruit['y']), fruit['size'], color=fruit['color'])) vy # Update fruit position x
ani = animation.FuncAnimation(fig, animate, frames=100, interval=100)
# Fruits properties fruits = [ {'x': 2, 'y': 2, 'size': 1, 'color': 'r'}, # Apple {'x': 5, 'y': 5, 'size': 2, 'color': 'g'}, # Banana {'x': 8, 'y': 8, 'size': 3, 'color': 'b'}, # Cherry ] 10) ani = animation.FuncAnimation(fig
fig, ax = plt.subplots()