22
33interface
44uses
5- U_Sort.DTO.Retangle,
6- FMX.Layouts, System.UITypes, System.SysUtils, FMX.Forms;
5+ U_Sort.DTO.Retangle, U_SortInterface,
6+ FMX.Layouts, System.UITypes, System.SysUtils, FMX.Forms, System.Classes ;
77
88type
9- TSortClass = class (TInterfacedObject)
9+ TSortClass = class (TInterfacedObject, ISortInterface )
1010 private
1111 const
1212 fTempo : Integer = 500 ;
13+ fQtdRet : Integer = 50 ;
14+
1315 var
1416 fCor : Cardinal;
1517 fCorBorda : Cardinal;
1618 fCorMudanca : Cardinal;
1719 fLargura : Integer;
1820 fLarguraBorda : Integer;
1921 fRaio : Integer;
20- fOwner : TLayout;
22+
2123 procedure criaRetangulo (posicao, posX, altura : integer);
2224 procedure preencheTela ();
2325 procedure colorChange (ret01, ret02 : TRetangulo);
2426
2527 protected
28+ var
29+ fOwner : TLayout;
30+
2631 constructor Create(Owner : TLayout);
32+
33+ procedure algoritmo (); Virtual ; Abstract ;
2734 procedure troca (ret01, ret02 : TRetangulo);
2835 function findRectangle (posicao : Integer) : TRetangulo;
36+
2937 property Distancia : Integer read fLargura;
3038
39+ public
40+ procedure sort ();
41+
3142 end ;
3243
3344implementation
@@ -54,9 +65,9 @@ constructor TSortClass.Create(Owner : TLayout);
5465 fCor := TAlphaColors.Hotpink;
5566 fCorBorda := TAlphaColors.Black;
5667 fCorMudanca := TAlphaColors.Skyblue;
57- fLargura := 25 ;
5868 fLarguraBorda := 1 ;
59- fRaio := 5 ;
69+ fLargura := trunc(Owner.Size.Width / fQtdRet);
70+ fRaio := trunc(fLargura * 0.20 );
6071 preencheTela();
6172
6273end ;
@@ -95,20 +106,34 @@ procedure TSortClass.preencheTela;
95106begin
96107 Randomize;
97108 posX := 0 ;
98- for i := 0 to 49 do
109+ for i := 1 to fQtdRet do
99110 begin
100111 repeat
101112 tamanho := Random(490 ) + 10
102113 until ((tamanho mod 5 ) = 0 );
103114
104- criaRetangulo(i, posX, tamanho);
115+ criaRetangulo(i - 1 , posX, tamanho);
105116 inc(posX, fLargura);
106-
107117 end ;
118+
108119 Application.ProcessMessages;
109120
110121end ;
111122
123+ procedure TSortClass.sort ;
124+ var
125+ alg : TThread;
126+
127+ begin
128+ alg := TThread.CreateAnonymousThread(
129+ procedure
130+ begin
131+ Self.algoritmo();
132+ end );
133+ alg.Start();
134+
135+ end ;
136+
112137procedure TSortClass.troca (ret01, ret02 : TRetangulo);
113138var
114139 aux : Single;
@@ -124,6 +149,9 @@ procedure TSortClass.troca(ret01, ret02 : TRetangulo);
124149 ret02.Height := aux;
125150 ret01.Position.Y := fOwner.Height - ret01.Height;
126151 ret02.Position.Y := fOwner.Height - ret02.Height;
152+ ret01.Repaint;
153+ ret02.Repaint;
154+ fOwner.Repaint;
127155
128156 finally
129157 Sleep(fTempo);
0 commit comments