
30.03.2010, 09:30
|
Активный
|
|
Регистрация: 12.09.2008
Сообщения: 391
Репутация: 6078
|
|
Я бы так сделал:
Код:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Spin, ExtCtrls;
type
TForm1 = class(TForm)
PaintBox1: TPaintBox;
SpinEdit1: TSpinEdit;
Label1: TLabel;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
procedure DrawDot(x, y: Integer);
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
ax: array[1..30] of Integer;
ay: array[1..30] of Integer;
implementation
{$R *.dfm}
procedure TForm1.DrawDot(x, y : Integer);
begin
// Ðèñóåì òî÷êó ñ ïåðåâîäîì îòñ÷åòà íóëåâîé òî÷êè
PaintBox1.Canvas.MoveTo(40 - x, 40 - y);
PaintBox1.Canvas.LineTo(40 - (x + 1), 40 - y);
end;
procedure TForm1.Button1Click(Sender: TObject);
var
i : Integer;
tx1, ty1, tx2, ty2, tx3, ty3 : Integer;
rect : TRect;
begin
// Î÷èùàåì îáëàñòü ðèñîâàíèÿ
rect.Left := 0;
rect.Top := 0;
rect.Bottom := 41;
rect.Right := 41;
PaintBox1.Canvas.Brush.Color := clBtnFace;
if SpinEdit1.Value > 30 then SpinEdit1.Value := 30;
PaintBox1.Canvas.FillRect(rect);
// Ãåíåðèðóåì è ðèñóåì òî÷êè
Randomize;
for i:= 1 to SpinEdit1.Value do
begin
ax[i] := random(40);
ay[i] := random(40);
DrawDot(ax[i], ay[i]);
end;
// Èùåì ñàìóþ âûñøóþ òî÷êó
tx1 := 0;
ty1 := 0;
for i:= 1 to SpinEdit1.Value do
begin
if ay[i] > ty1 then
begin
ty1 := ay[i];
tx1 := ax[i];
end;
end;
// Èùåì ñàìóþ ëåâóþ òî÷êó
tx2 := 40;
ty2 := 0;
for i:= 1 to SpinEdit1.Value do
begin
if ax[i] < tx2 then
begin
ty2 := ay[i];
tx2 := ax[i];
end;
end;
// Èùåì ñàìóþ ïðàâóþ òî÷êó
tx3 := 0;
ty3 := 0;
for i:= 1 to SpinEdit1.Value do
begin
if ax[i] > tx3 then
begin
ty3 := ay[i];
tx3 := ax[i];
end;
end;
// Ñòðîèì ïî íàéäåííûì òî÷êàì òðåóãîëüíèê
PaintBox1.Canvas.MoveTo(40 - tx1, 40 - ty1);
PaintBox1.Canvas.LineTo(40 - tx2, 40 - ty2);
PaintBox1.Canvas.LineTo(40 - tx3, 40 - ty3);
PaintBox1.Canvas.LineTo(40 - tx1, 40 - ty1);
end;
end.
|