-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathsorting_with_annimation_visualization_multi.py
More file actions
53 lines (39 loc) · 1.26 KB
/
sorting_with_annimation_visualization_multi.py
File metadata and controls
53 lines (39 loc) · 1.26 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
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.text import Text
import threading
from matplotlib.animation import FuncAnimation, PillowWriter
import time
import sys
from modules.multithread.MultiThreadCellForVisualize import MultiThreadCellForVisualize
VALUE_LIST = [28, 34, 6, 20, 7, 89, 34, 18, 29, 51]
threadLock = threading.Lock()
fig, ax = plt.subplots()
plt.xlim(0, 12)
plt.ylim(0, 3)
ax.get_xaxis().set_visible(False)
ax.get_yaxis().set_visible(False)
cells = []
for i in range(0, len(VALUE_LIST)):
cell = MultiThreadCellForVisualize(i, VALUE_LIST[i], threadLock, (i + 1, 1.5), 'x distance')
cell.neighbors = cells
cells.append(cell)
for cell in cells:
cell.plot_cell(ax)
# def update(_, cs):
# cells_in_moving = [cell for cell in cs if cell.is_moving]
# if cells_in_moving:
# for cell in cells_in_moving:
# cell.move()
# return cs
# for cell in cs:
# if cell.should_move_to_right():
# cell.move_to_right()
# return cs
for cell in cells:
cell.start()
plt.show()
# ani = FuncAnimation(fig, update, 300, fargs=([cells]), interval=50, blit=False)
# f = "visual_gifs/cell_sorting_1d.gif"
# writergif = PillowWriter(fps=30)
# ani.save(f, writer=writergif)