@@ -37,16 +37,12 @@ def __init__(self, root, title) -> None:
3737 self .start .grid (column = 5 , row = 2 , padx = 5 , pady = 5 )
3838
3939 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 ,
4441 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 )
4643
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 )
5046
5147 # Canvas
5248 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):
8379 def slide_function (self ):
8480 self .N = int (self .arraysize .get ())
8581 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 ()
8783 self .colours = ['dodgerblue' for _ in range (self .N )]
8884 self .shuffle ()
8985
@@ -229,12 +225,16 @@ def start(self):
229225 min_index = i
230226 # loop to find the minimum element and its index
231227 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 )])
233229 time .sleep (self .speed )
234230 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 )
235233 min_index = j
236234 if min_index != i :
237235 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 )
238238 self .display (self .N ,self .data ,['lime' for _ in range (self .N )])
239239
240240
0 commit comments