fork download
  1. import matplotlib.pyplot as plt
  2. import matplotlib.animation as animation
  3. import numpy as np
  4.  
  5. # Parameters
  6. n = 100
  7. positions = list(range(1, n + 1))
  8. angle = np.linspace(0, 2 * np.pi, n, endpoint=False)
  9.  
  10. # Set up figure
  11. fig, ax = plt.subplots(figsize=(8, 8))
  12. ax.axis('off')
  13. sc = ax.scatter([], [], s=400)
  14.  
  15. # Annotate numbers
  16. texts = []
  17. for i in range(n):
  18. x, y = np.cos(angle[i]), np.sin(angle[i])
  19. txt = ax.text(x, y, str(i+1), ha='center', va='center', fontsize=8, color='white',
  20. bbox=dict(boxstyle='circle,pad=0.3', fc='blue', ec='black', lw=1))
  21. texts.append(txt)
  22.  
  23. # State variables
  24. current_index = 0
  25.  
  26. def update(frame):
  27. global current_index, positions, texts
  28.  
  29. if len(positions) <= 1:
  30. return
  31.  
  32. # Calculate index of person to be removed
  33. remove_index = (current_index + 1) % len(positions)
  34.  
  35. # Remove from display
  36. texts[positions[remove_index] - 1].set_visible(False)
  37.  
  38. # Remove from list
  39. del positions[remove_index]
  40.  
  41. # Next killer
  42. current_index = remove_index % len(positions)
  43.  
  44. # Redraw remaining people
  45. new_angle = np.linspace(0, 2 * np.pi, len(positions), endpoint=False)
  46. for i, pos in enumerate(positions):
  47. x, y = np.cos(new_angle[i]), np.sin(new_angle[i])
  48. texts[pos - 1].set_position((x, y))
  49.  
  50. ani = animation.FuncAnimation(fig, update, frames=100, interval=700, repeat=False)
  51. plt.show()
Success #stdin #stdout 0.78s 58164KB
stdin
Standard input is empty
stdout
Standard output is empty