def animate(i): global vx, vy # Update fruit position x, y = fruit.get_data() x += vx y += vy
# Bounce off edges if x < 0 or x > 10: vx *= -1 if y < 0 or y > 10: vy *= -1 Fruitydelicious animations (11.02.2023)
import numpy as np import matplotlib.pyplot as plt import matplotlib.animation as animation def animate(i): global vx, vy # Update fruit
fig, ax = plt.subplots()
# 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 ] def animate(i): global vx