Предмет:
Тип роботи:
Звіт з практики
К-сть сторінок:
46
Мова:
Українська
Shift: TShiftState; X, Y: Integer);
procedure N1Click(Sender: TObject);
procedure FormMouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
procedure N2Click(Sender: TObject);
procedure N3Click(Sender: TObject);
private
info:string;
k:integer;
square:real;
a,b,c,d:real;
xr,yr,zr,gr:real;
pol:array[1..4] of Tpoint;
function check(a,b,c,d:Tpoint):boolean;
function length(a,b:Tpoint):real;
function corner(aa,bb,cc:Tpoint):real;
function checksquare:boolean;
function checkrect:boolean;
function checkromb:boolean;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
function tform1.checkromb:boolean;
begin
if (a=b)and(b=c)and(c=d)and(d=a) then begin square:=1/2*length(pol[1],pol[3])*length(pol[2],pol[4]); result:=true end else result:=false;
end;
function Tform1.corner(aa,bb,cc:Tpoint):real;
var a1,a2:tpoint;cos:real;
begin
a1.X:=aa.X-cc.X;
a1.Y:=aa.Y-cc.Y;
a2.X:=bb.X-cc.X;
a2.Y:=bb.Y-cc.Y;
cos:=(a1.X*a2.X+a1.Y*a2.Y)/(sqrt( sqr(a1.X)+sqr(a1.y))*sqrt(sqr(a2.X)+sqr(a2.Y)));
result:=round(arccos(cos)*180/pi);
end;
function tform1.checkrect:boolean;
begin
if ((a=c)and(b=d))and((xr=yr)and(yr=zr)and(zr=gr)and(gr=xr)) then begin result:=true; square:=a*c; end else result:=false;
end;
function Tform1.checksquare:boolean;
begin
if ((a=d)and(d=b)and(b=c)and(c=a))and((xr=yr)and(yr=zr)and(zr=gr)and(gr=xr)) then begin result:=true; square:=a*a; end else result:=false;
end;
function Tform1.length(a,b:Tpoint):real;
begin
result:=sqrt(sqr(a.X-b.X)+sqr(a.Y-b.Y));
end;
function Tform1.check(a: TPoint; b: TPoint;c: TPoint;d: TPoint):boolean;
var A1,B1,C1,A2,B2,C2:integer;
begin
A1:=(d.x-c.x)*(a.y-c.y)-(d.y-c.y)*(a.x-c.x);
B1:=(d.x-c.x)*(b.y-c.y)-(d.y-c.y)*(b.x-c.x);
A2:=(b.x-a.x)*(c.y-a.y)-(b.y-a.y)*(c.x-a.x);
B2:=(b.x-a.x)*(d.y-a.y)-(b.y-a.y)*(d.x-a.x);
Result := (A1 * B1 < 0) and (A2 * B2 < 0);
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
k:=1;
end;
procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
var p:tpoint; i,j:integer; sort:array[1..4]of tpoint; l:real;
begin
if k<=4 then begin
form1.Canvas.Pixels[x,y]:=clblack;
pol[k].x:=x; pol[k].y:=y;
k:=k+1;
end
else begin
for j := 1 to 4 do
for i := 1 to 3 do if (pol[i].X>pol[i+1].x) then begin p:=pol[i+1]; pol[i+1]:=pol[i]; pol[i]:=p;end;
if (not(check(pol[1],pol[2],pol[3],pol[4])))and(not(check(pol[1],pol[4],pol[2],pol[3]))) then form1.Canvas.Polygon(pol)
else begin p:=pol[1]; pol[1]:=pol[4]; pol[4]:=p;
if (not(check(pol[1],pol[2],pol[3],pol[4])))and(not(check(pol[1],pol[4],pol[2],pol[3]))) then form1.Canvas.Polygon(pol)
else begin p:=pol[1]; pol[1]:=pol[2]; pol[2]:=p;
if (not(check(pol[1],pol[2],pol[3],pol[4])))and(not(check(pol[1],pol[4],pol[2],pol[3]))) then form1.Canvas.Polygon(pol)end
end;
a:=length(pol[1],pol[2])/37.79527559055;
b:=length(pol[2],pol[3])/37.79527559055;
c:=length(pol[3],pol[4])/37.79527559055;
d:=length(pol[4],pol[1])/37.79527559055;
xr:=corner(pol[2],pol[4],pol[1]);
yr:=corner(pol[1],pol[3],pol[4]);
zr:=corner(pol[4],pol[2],pol[3]);
gr:=corner(pol[3],pol[1],pol[2]);
if checksquare then info:='квадрат' else
if checkromb then info:='ромб' else
if checkrect then info:='прямокутник' else begin l:=(a+b+c+d)/2; square:=sqrt((l-a)*(l-b)*(l-c)*(l-d)-a*b*c*d*cos((xr+zr)/2)); info:='чотирикутник';end;
end;
end;
procedure TForm1.N1Click(Sender: TObject);
begin
PatBlt(Form1.Canvas.Handle, 0, 0, Form1.ClientWidth, Form1.ClientHeight, WHITENESS);
k:=1;
end;
procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
begin
statusbar1.SimpleText :='x: '+inttostr(x)+ ' y: '+inttostr(y);
end;
procedure TForm1.N2Click(Sender: TObject);
var p:real;
begin
if k=5 then begin p:=a+b+c+d; showmessage(info+' площа: '+floattostr((square))+'см периметр: '+floattostr((p))+'см');end else showmessage('спочатку намалюйте обєкт');
end;
procedure TForm1.N3Click(Sender: TObject);
begin
close;
end;
end.
14 Програма, яка при натиску мишки на вікно переставляє дві кульки, так, щоб вони не перетиналися
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls;
type
TForm1 = class(TForm)
Shape1: TShape;
Shape2: TShape;
procedure Shape2MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure Shape1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure FormMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
var x0,y0:integer;
begin randomize;
Shape1.Top:=random(Form1.clientheight-Shape1.height);
Shape1.Left:=random(Form1.clientwidth-Shape1.width);
y0:=random(Form1.clientheight-Shape2.height);
x0:=random(Form1.clientwidth-Shape2.width);
while not(((Shape1.left+Shape1.Width<x0)or(Shape1.left-Shape2.Width>x0))and((Shape1.Top+Shape1.Height<y0)or(Shape1.Top-Shape2.Height>y0))) do
begin y0:=random(Form1.clientheight-Shape2.height);
x0:=random(Form1.clientwidth-Shape2.width);end;
Shape2.Top:=y0;
Shape2.Left:=x0;
end;
procedure TForm1.Shape1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
var x0,y0:integer;
begin randomize;
Shape1.Top:=random(Form1.clientheight-Shape1.height);
Shape1.Left:=random(Form1.clientwidth-Shape1.width);
y0:=random(Form1.clientheight-Shape2.height);
x0:=random(Form1.clientwidth-Shape2.width);
while not(((Shape1.left+Shape1.Width<x0)or(Shape1.left-Shape2.Width>x0))and((Shape1.Top+Shape1.Height<y0)or(Shape1.Top-Shape2.Height>y0))) do
begin y0:=random(Form1.clientheight-Shape2.height);
x0:=random(Form1.clientwidth-Shape2.width);end;
Shape2.Top:=y0;