-
-
Notifications
You must be signed in to change notification settings - Fork 32.7k
Closed as not planned
Labels
Description
Bug report
Bug description:
# Add a code block here, if required
```import subprocess
import sys
# Function to install required libraries
def install(package):
subprocess.check_call([sys.executable, "-m", "pip", "install", package])
# Try importing libraries, install if missing
try:
import matplotlib.pyplot as plt
except ImportError:
print("Installing matplotlib...")
install("matplotlib")
import matplotlib.pyplot as plt
try:
import numpy as np
except ImportError:
print("Installing numpy...")
install("numpy")
import numpy as np
try:
import matplotlib.animation as animation
except ImportError:
print("Installing matplotlib.animation...")
install("matplotlib")
import matplotlib.animation as animation
try:
from PIL import Image
except ImportError:
print("Installing pillow...")
install("pillow")
from PIL import Image
# --- Spin Wheel Script ---
names = [
"Liang", "Li Xing", "Ah Yang", "Lida", "Ahao", "Suli", "Moni",
"Panha", "Prum Barara", "Illslick", "Makala", "Luffy", "Hongle",
"Ahnan", "AhXin"
]
N = len(names)
colors = plt.cm.tab20(np.linspace(0, 1, N))
fig, ax = plt.subplots(figsize=(6, 6), subplot_kw=dict(aspect="equal"))
def draw_wheel(angle):
ax.clear()
wedges, _ = ax.pie(
[1]*N, colors=colors, startangle=angle, counterclock=False,
wedgeprops=dict(width=0.3)
)
for i, p in enumerate(wedges):
ang = (p.theta2 - p.theta1)/2. + p.theta1
y = np.sin(np.deg2rad(ang))
x = np.cos(np.deg2rad(ang))
ha = {-1: "right", 1: "left"}[int(np.sign(x))]
ax.text(x*1.1, y*1.1, names[i], ha=ha, va="center",
fontsize=8, weight="bold", rotation=ang,
rotation_mode="anchor")
# Add triangle pointer
pointer = plt.Polygon([[-0.05, 1.05], [0.05, 1.05], [0, 1.2]], closed=True, color="red")
ax.add_patch(pointer)
ax.set_title("Spin Wheel", fontsize=14, weight="bold")
# Spin with deceleration
frames = 100
angles = np.cumsum(np.linspace(20, 1, frames)) # start fast, slow down
ani = animation.FuncAnimation(fig, lambda i: draw_wheel(angles[i]),
frames=frames, interval=100)
# Save GIF
gif_filename = "spin_wheel_slowdown.gif"
ani.save(gif_filename, writer="pillow", dpi=80)
plt.close()
print(f"✅ Spinning wheel GIF saved as {gif_filename}")
### CPython versions tested on:
3.9
### Operating systems tested on:
Windows