@@ -37,16 +37,12 @@ def __init__(self, root, title) -> None:
37
37
self .start .grid (column = 5 ,row = 2 ,padx = 5 ,pady = 5 )
38
38
39
39
ttk .Label (self .root ,text = 'Speed & Array Size:' ).grid (row = 2 ,column = 0 )
40
- self .timespan = ttk .Scale (self .root ,from_ = 1 ,to = 1000 ,value = 0.2 ,style = 'success.Horizontal.TScale' ,length = 250 ,
41
- command = lambda x :self .slide_function ())
42
- self .timespan .grid (row = 2 ,column = 1 ,columnspan = 2 )
43
- self .arraysize = ttk .Scale (self .root ,from_ = 6 ,to = 120 ,length = 250 ,style = 'success.Horizontal.TScale' ,value = 10 ,
40
+ self .arraysize = ttk .Scale (self .root ,from_ = 6 ,to = 120 ,length = 380 ,style = 'success.Horizontal.TScale' ,value = 10 ,
44
41
command = lambda x :self .slide_function ())
45
- self .arraysize .grid (row = 2 ,column = 3 ,columnspan = 2 )
42
+ self .arraysize .grid (row = 2 ,column = 1 ,columnspan = 3 )
46
43
47
- self .shuf = ttk .Button (self .root ,text = 'Shuffle' ,style = 'info.Outline.TButton' ,padding = 5 ,width = 15 ,
48
- command = self .shuffle )
49
- self .shuf .grid (column = 5 ,row = 1 ,padx = 5 ,pady = 5 )
44
+ ttk .Button (self .root ,text = 'Shuffle' ,style = 'info.Outline.TButton' ,padding = 5 ,width = 15 ,
45
+ command = self .shuffle ).grid (column = 5 ,row = 1 ,padx = 5 ,pady = 5 )
50
46
51
47
# Canvas
52
48
self .canvas = Canvas (self .root ,width = 800 - 5 ,height = 400 ,highlightbackground = "dodgerblue" ,highlightthickness = 2 ,
@@ -83,7 +79,7 @@ def display(self,N: int,a: list,rong: list):
83
79
def slide_function (self ):
84
80
self .N = int (self .arraysize .get ())
85
81
self .data = np .linspace (5 ,400 ,self .N ,dtype = np .uint16 )
86
- self .speed = 1 / self .timespan .get ()
82
+ self .speed = 5 / self .arraysize .get ()
87
83
self .colours = ['dodgerblue' for _ in range (self .N )]
88
84
self .shuffle ()
89
85
@@ -229,12 +225,16 @@ def start(self):
229
225
min_index = i
230
226
# loop to find the minimum element and its index
231
227
for j in range (i + 1 ,len (self .data )):
232
- self .display (self .N ,self .data ,['purple ' if a == min_index else 'green' if a <= i else 'dodgerblue' for a in range (self .N )])
228
+ self .display (self .N ,self .data ,['yellow ' if a == min_index or a == i else 'green' if a <= i else 'dodgerblue' for a in range (self .N )])
233
229
time .sleep (self .speed )
234
230
if self .data [min_index ]> self .data [j ]:
231
+ self .display (self .N ,self .data ,['red' if a == min_index or a == i else 'green' if a <= i else 'dodgerblue' for a in range (self .N )])
232
+ time .sleep (self .speed )
235
233
min_index = j
236
234
if min_index != i :
237
235
self .data [i ],self .data [min_index ]= self .data [min_index ],self .data [i ]
236
+ self .display (self .N ,self .data ,['lime' if a == min_index or a == i else 'green' if a <= i else 'dodgerblue' for a in range (self .N )])
237
+ time .sleep (self .speed )
238
238
self .display (self .N ,self .data ,['lime' for _ in range (self .N )])
239
239
240
240