-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcircular_write.py
More file actions
73 lines (59 loc) · 2.38 KB
/
circular_write.py
File metadata and controls
73 lines (59 loc) · 2.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.animation import FuncAnimation, PillowWriter
# Settings for the circle of boxes
num_boxes = 12
box_radius = 10
box_size = 4
colors = ["white"] * num_boxes # Initial color for each box
values = [""] * num_boxes # Values stored in each box
red_start = None # Marks when a launch is detected
# Circular positions for boxes
angles = np.linspace(2 * np.pi, 0, num_boxes, endpoint=False)
positions = [(box_radius * np.cos(angle), box_radius * np.sin(angle)) for angle in angles]
# Create figure and axes
fig, ax = plt.subplots(figsize=(6, 6))
ax.set_xlim(-box_radius - 2, box_radius + 2)
ax.set_ylim(-box_radius - 2, box_radius + 2)
ax.set_aspect('equal')
plt.axis('off')
# Draw the boxes
patches = [plt.Circle(pos, box_size // 2, edgecolor='black') for pos in positions]
for patch in patches:
ax.add_patch(patch)
# Text annotations for values
texts = [ax.text(x, y, "", ha="center", va="center", fontsize=18) for x, y in positions]
# Central text for "Launch Detected"
launch_text = ax.text(0, 0, "", ha="center", va="center", fontsize=20, color="red")
pre_launch_text = ax.text(0, 0, "Pre-Launch", ha="center", va="center", fontsize=20, color="green")
# Animation function
def update(frame):
global red_start
current_index = frame % num_boxes
# Stop animation if we reach back to the starting red box
if colors[current_index] == "red":
return
# If a launch was detected, all boxes after that point are write-protected (red)
if red_start is not None:
colors[current_index] = "red"
launch_text.set_text("Launch Detected")
elif red_start is None and frame == 30:
colors[current_index] = "red"
red_start = current_index
launch_text.set_text("Launch Detected")
pre_launch_text.set_text("")
else:
colors[current_index] = "yellow" # Highlight during update
if colors[(frame - 1) % num_boxes] == "yellow":
colors[(frame - 1) % num_boxes] = "green"
# Update value in the current box
values[current_index] = str(frame)
# Update visuals
for i, patch in enumerate(patches):
patch.set_facecolor(colors[i])
texts[i].set_text(values[i])
# Create animation
ani = FuncAnimation(fig, update, frames=50, interval=300)
# Save to GIF
gif_path = 'circular_data_saving_with_launch.gif'
ani.save(gif_path, writer=PillowWriter(fps=3))