编写一个delphi根据三角形的三个顶点画出一个三角形
2个回答
展开全部
unit Unit1;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs;
type
TForm1 = class(TForm)
procedure FormMouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
q:array[1..3,1..2]of longint;
flag:boolean;
n:longint;
implementation
{$R *.dfm}
procedure drawTriangle();
begin
form1.Canvas.MoveTo(q[1,1],q[1,2]);
form1.Canvas.LineTo(q[2,1],q[2,2]);
form1.Canvas.MoveTo(q[2,1],q[2,2]);
form1.Canvas.LineTo(q[3,1],q[3,2]);
form1.Canvas.MoveTo(q[3,1],q[3,2]);
form1.Canvas.LineTo(q[1,1],q[1,2]);
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
flag:=false;
n:=0;
end;
procedure TForm1.FormMouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
inc(n);
if n=4 then n:=1;
q[n,1]:=x;
q[n,2]:=y;
if (not flag) and (n=3) then flag:=true;
self.Repaint;
if flag then drawTriangle();
end;
end.
Unit主代码
其他的你会自己弄吧,也没用什么控件
纯正Delphi哦,Delphi XE5下编写
使用方法,Form生成之后直接在Form上面点三个点,就画出了这三个点的三角形,是不是很方便呢
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2015-01-18
展开全部
用lazarus编制,和delphi类似,x坐标不超过900,y坐标不超过600。若超过,同比例缩小即可。
unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls;
type
{ TForm1 }
TForm1 = class(TForm)
Button1: TButton;
Edit1: TEdit;
Edit2: TEdit;
Edit3: TEdit;
Edit4: TEdit;
Edit5: TEdit;
Edit6: TEdit;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ private declarations }
public
{ public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.lfm}
{ TForm1 }
procedure TForm1.FormCreate(Sender: TObject);
begin
end;
procedure TForm1.Button1Click(Sender: TObject);
var
x1,y1,x2,y2,x3,y3:real;
begin
val(edit1.Text,x1);
val(edit2.text,y1);
val(edit3.text,x2);
val(edit4.text,y2);
val(edit5.Text,x3);
val(edit6.text,y3);
canvas.Line(trunc(x1),600-trunc(y1),trunc(x2),600-trunc(y2));
canvas.Line(trunc(x1),600-trunc(y1),trunc(x3),600-trunc(y3));
canvas.Line(trunc(x2),600-trunc(y2),trunc(x3),600-trunc(y3));
end;
end.
unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls;
type
{ TForm1 }
TForm1 = class(TForm)
Button1: TButton;
Edit1: TEdit;
Edit2: TEdit;
Edit3: TEdit;
Edit4: TEdit;
Edit5: TEdit;
Edit6: TEdit;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ private declarations }
public
{ public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.lfm}
{ TForm1 }
procedure TForm1.FormCreate(Sender: TObject);
begin
end;
procedure TForm1.Button1Click(Sender: TObject);
var
x1,y1,x2,y2,x3,y3:real;
begin
val(edit1.Text,x1);
val(edit2.text,y1);
val(edit3.text,x2);
val(edit4.text,y2);
val(edit5.Text,x3);
val(edit6.text,y3);
canvas.Line(trunc(x1),600-trunc(y1),trunc(x2),600-trunc(y2));
canvas.Line(trunc(x1),600-trunc(y1),trunc(x3),600-trunc(y3));
canvas.Line(trunc(x2),600-trunc(y2),trunc(x3),600-trunc(y3));
end;
end.
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询