TDravRandom = class(TThread)
private
{ Private declarations }
MyImage: TImage;
protected
procedure Execute; override;
procedure ShowResult; //
end;
procedure TDravRandom.Execute;
var
Iter:Integer;
i,X,Y:Integer;
Rr,delt,skl:Real;
x0,y0:integer;
share_r,ratio:real;
r:integer;
begin
DrawingRandom:=True;
// while (DrawingFile=-1) and (not Terminated) do
MyImage:=TImage.Create(nil);
MyImage.Width:=CoreShell.Image1.Width;
MyImage.Height:=CoreShell.Image1.Height;
Iter:=0;
while (DrawingFile=-1) and (not Terminated) do
begin
MyImage.Width:=CoreShell.Image1.Width;
MyImage.Height:=CoreShell.Image1.Height;
MyImage.Canvas.Lock;
Rr:=1e10;
for i:=2 to InitialData.fa_location.NVig do //для масштабирования картинки
begin
delt:=Sqrt(((InitialData.fa_location.TVSCord[i].x-InitialData.fa_location.TVSCord[1].x)*(InitialData.fa_location.TVSCord[i].x-InitialData.fa_location.TVSCord[1].x))+
((InitialData.fa_location.TVSCord[i].y-InitialData.fa_location.TVSCord[1].y)*(InitialData.fa_location.TVSCord[i].y-InitialData.fa_location.TVSCord[1].y)));
if delt<Rr then Rr:=delt/2;
end;
skl:=3700/MyImage.Height; //масштаб
r:=Round(1130*Rr/(skl)*0.9); //радиус шестигранника
ratio:=r/GlTuningImage.ReloadTuning.ratio;
MyImage.Canvas.Pen.Color:=clBlack;
MyImage.Canvas.Font.Size:=Round(GlTuningImage.ReloadTuning.text[1].frontsize*2*ratio);
x0:=Round(1*(MyImage.Width)/2); //центр
y0:=Round(1*(MyImage.Height)/2);
Inc(iter);
MyImage.Canvas.TextOut (10,10,inttostr(Iter)); //вывожу итерации просто чтоб понять когда зависло
Draw_random_core_in_thread (MyImage,x0,y0,r,Rr,skl,ratio);
MyImage.Canvas.UnLock;
// if CoreShell.TreeView1.Selected.Index<>0 then exit;
Synchronize(ShowResult);
MyImage.Picture:=nil;
Sleep(10); //так часто чтоб быстрее зависло, иначе часами ждать можно
end;
DrawingRandom:=false;
end;
procedure TDravRandom.ShowResult;
begin
CoreShell.Image1.Picture:=MyImage.Picture;
end;
Ну и вызываемые процедурки:
procedure Draw_random_core_in_thread (TempImage:TImage;x0,y0,r:integer; Rr,skl,ratio:Real);
var
i,X,Y:Integer;
delt:Real;
// x0,y0:integer;
// r:integer;
begin
for i:=1 to InitialData.fa_location.NTVS do//
begin
X:=Round(x0+1000*InitialData.fa_location.TVSCord[i].x/skl);
Y:=Round(y0-1000*InitialData.fa_location.TVSCord[i].y/skl);
TempImage.Canvas.Brush.Color:=RGB(Random(100)+150, Random(100)+150, Random(100)+150);
DrawPolygon (r,X,Y,TempImage.Canvas);
TempImage.Canvas.Brush.Style := bsClear;
TempImage.Canvas.TextOut( Round(X-TempImage.Canvas.TextWidth(inttostr(i))/2+GlTuningImage.ReloadTuning.text[1].Location.X*ratio),
Round(Y+GlTuningImage.ReloadTuning.text[1].Location.Y*ratio),
inttostr(i));
end;
end;
procedure DrawPolygon (r,x0,y0:Integer;Sender: TObject); //рисуем многоугольник радиуса Р в точке Х0У0
var
a:array[1..6] of TPoint;
i:Integer;
begin
for i:=1 to 6 do
begin
a[i].X:=Round(r*cos(i*2*pi/6+pi/2)+x0);
a[i].Y:=Round(r*sin(i*2*pi/6+pi/2)+y0);
end;
(Sender as Tcanvas).Polygon(a);
end;
|