Міністерство освіти та науки України
Національний університет “Львівська політехніка”
Інститут комп’ютерних наук та інформаційних технологій
Кафедра автоматизованих систем управління
Лабораторна робота №1
з дисципліни “ Комп`ютерна графіка ”
Тема: «Робота в декартовій
системі координат»
Програмна реалізація:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls, ComCtrls, ToolWin;
type
TForm1 = class(TForm)
PaintBox1: TPaintBox;
PageControl1: TPageControl;
TabSheet1: TTabSheet;
TabSheet2: TTabSheet;
TabSheet3: TTabSheet;
Button1: TButton;
LabeledEdit1: TLabeledEdit;
LabeledEdit2: TLabeledEdit;
LabeledEdit3: TLabeledEdit;
LabeledEdit4: TLabeledEdit;
LabeledEdit5: TLabeledEdit;
LabeledEdit6: TLabeledEdit;
Button2: TButton;
LabeledEdit7: TLabeledEdit;
LabeledEdit8: TLabeledEdit;
Button3: TButton;
LabeledEdit9: TLabeledEdit;
LabeledEdit10: TLabeledEdit;
LabeledEdit11: TLabeledEdit;
LabeledEdit12: TLabeledEdit;
Button4: TButton;
LabeledEdit13: TLabeledEdit;
LabeledEdit14: TLabeledEdit;
LabeledEdit15: TLabeledEdit;
LabeledEdit16: TLabeledEdit;
LabeledEdit17: TLabeledEdit;
LabeledEdit18: TLabeledEdit;
Button5: TButton;
LabeledEdit19: TLabeledEdit;
LabeledEdit20: TLabeledEdit;
LabeledEdit21: TLabeledEdit;
LabeledEdit22: TLabeledEdit;
Button6: TButton;
LabeledEdit23: TLabeledEdit;
LabeledEdit24: TLabeledEdit;
LabeledEdit25: TLabeledEdit;
LabeledEdit26: TLabeledEdit;
function y(a:integer):integer;
procedure draw_axises();
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
procedure Button5Click(Sender: TObject);
procedure Button6Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
xc,yc:integer;
llength,wwidth:integer;
implementation
{$R *.dfm}
function TForm1.y(a:integer):integer;
begin
y:=((PaintBox1.Height div 2)-a);
end;
procedure TForm1.draw_axises();
var
x,y,i:integer;
//xc,yc:integer;
//length,width:integer;
begin
xc:=PaintBox1.Width div 2;
yc:=PaintBox1.Height div 2;
llength:=PaintBox1.Height div 40;
wwidth:=6;
with PaintBox1.Canvas do
begin
//Ellipse(1,1,44,66);
PaintBox1.Refresh;
Pen.Color:=clBlack;
MoveTo(0,yc);
LineTo(PaintBox1.Width,yc);
MoveTo(xc,0);
LineTo(xc,(PaintBox1.Width));
//MoveTo(0,yc);
//LineTo(45,34);
x:=xc;
while (x>0) do
begin
MoveTo(x,yc-wwidth);
LineTo(x,yc+wwidth);
x:=x-llength;
end;
x:=xc;
while (x<PaintBox1.Width) do
begin
MoveTo(x,yc-wwidth);
LineTo(x,yc+wwidth);
x:=x+llength;
end;
y:=yc;
while (y>0) do
begin
MoveTo(xc-wwidth,y);
LineTo(xc+wwidth,y);
y:=y-llength;
end;
y:=yc;
while (y<PaintBox1.Height) do
begin
MoveTo(xc-wwidth,y);
LineTo(xc+wwidth,y);
y:=y+llength;
end;
TextOut(round(PaintBox1.Width*0.98),round(yc*1.1),'X');
TextOut(round(xc*1.05),round(PaintBox1.Height*0.02),'Y');
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
xp,yp:integer;
point_size:integer;
// a,b,c,d:double;
begin
draw_axises();
point_size:=2;
xp:=strtoint(LabeledEdit1.Text);
yp:=strtoint(LabeledEdit2.Text);
with PaintBox1.Canvas do
begin
Pen.Color:=clRed;
//Pen.Width:=Pen.Width*2;
Ellipse(xp*llength+xc-point_size,yc-yp*llength-point_size,
xc+xp*llength+point_size,yc-yp*llength+point_size);
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
var
xp,yp:integer;
point_size:integer;
a,b,c,d:double;
begin
Button1.Click;
//draw_axises();
point_size:=2;
a:=strtofloat(LabeledEdit3.Text);
b:=strtofloat(LabeledEdit4.Text);
c:=strtofloat(LabeledEdit5.Text);
d:=strtofloat(LabeledEdit6.Text);
xp:=strtoint(LabeledEdit1.Text);
yp:=strtoint(LabeledEdit2.Text);
xp:=round(xp*a+yp*c);
yp:=round(xp*b+yp*d);
with PaintBox1.Canvas do
begin
Pen.Color:=clGreen;
//Pen.Width:=Pen.Width*2;
Ellipse(xp*llength+xc-point_size,yc-yp*llength-point_size,
xc+xp*llength+point_size,yc-yp*llength+point_size);
end;
end;
procedure TForm1.Button3Click(Sender: TObject);
var
xp1,yp1,xp2,yp2:integer;
point_size:integer;
// a,b,c,d:double;
begin
draw_axises();
point_size:=2;
xp1:=strtoint(LabeledEdit7.Text);
yp1:=strtoint(LabeledEdit8.Text);
xp2:=strtoint(LabeledEdit13.Text);
yp2:=strtoint(LabeledEdit14.Text);
with PaintBox1.Canvas do
begin
Pen.Color:=clRed;
//Pen.Width:=Pen.Width*2;
Ellipse(xp1*llength+xc-point_size,yc-yp1*llength-point_size,
xc+xp1*llength+point_size,yc-yp1*llength+point_size);
MoveTo(xp1*llength+xc,yc-yp1*llength);
LineTo(xc+xp2*llength,yc-yp2*llength);
Ellipse(xp2*llength+xc-point_size,yc-yp2*llength-point_size,
xc+xp2*llength+point_size,yc-yp2*llength+point_size);
end;
end;
procedure TForm1.Button4Click(Sender: TObject);
var
xp1,yp1,xp2,yp2:integer;
point_size:integer;
a,b,c,d:double;
begin
Button3.Click;
//draw_axises();
point_size:=2;
a:=strtofloat(LabeledEdit9.Text);
b:=strtofloat(LabeledEdit11.Text);
c:=strtofloat(LabeledEdit10.Text);
d:=strtofloat(LabeledEdit12.Text);
xp1:=strtoint(LabeledEdit7.Text);
yp1:=strtoint(LabeledEdit8.Text);
xp2:=strtoint(LabeledEdit13.Text);
yp2:=strtoint(LabeledEdit14.Text);
xp1:=round(xp1*a+yp1*c);
yp1:=round(xp1*b+yp1*d);
xp2:=round(xp2*a+yp2*c);
yp2:=round(xp2*b+yp2*d);
with PaintBox1.Canvas do
begin
Pen.Color:=clGreen;
Ellipse(xp1*llength+xc-point_size,yc-yp1*llength-point_size,
xc+xp1*llength+point_size,yc-yp1*llength+point_size);
MoveTo(xp1*llength+xc,yc-yp1*llength);
LineTo(xc+xp2*llength,yc-yp2*llength);
Ellipse(xp2*llength+xc-point_size,yc-yp2*llength-point_size,
xc+xp2*llength+point_size,yc-yp2*llength+point_size);
end;
end;
procedure TForm1.Button5Click(Sender: TObject);
var
xp1,yp1,xp2,yp2,xp3,yp3:integer;
point_size:integer;
a,b,c,d,n,m:double;
begin
//Button5.Click;
draw_axises();
point_size:=2;
a:=strtofloat(LabeledEdit19.Text);
b:=strtofloat(LabeledEdit20.Text);
c:=strtofloat(LabeledEdit21.Text);
d:=strtofloat(LabeledEdit22.Text);
xp1:=strtoint(LabeledEdit15.Text);
yp1:=strtoint(LabeledEdit17.Text);
xp2:=strtoint(LabeledEdit16.Text);
yp2:=strtoint(LabeledEdit18.Text);
xp3:=strtoint(LabeledEdit23.Text);
yp3:=strtoint(LabeledEdit24.Text);
{xp1:=round(xp1*a+yp1*c);
yp1:=round(xp1*b+yp1*d);
xp2:=round(xp2*a+yp2*c);
yp2:=round(xp2*b+yp2*d);
xp3:=round(xp3*a+yp3*c);
yp3:=round(xp3*b+yp3*d);}
with PaintBox1.Canvas do
begin
Pen.Color:=clRed;
Ellipse(xp1*llength+xc-point_size,yc-yp1*llength-point_size,
xc+xp1*llength+point_size,yc-yp1*llength+point_size);
MoveTo(xp1*llength+xc,yc-yp1*llength);
LineTo(xc+xp2*llength,yc-yp2*llength);
Ellipse(xp2*llength+xc-point_size,yc-yp2*llength-point_size,
xc+xp2*llength+point_size,yc-yp2*llength+point_size);
MoveTo(xp2*llength+xc,yc-yp2*llength);
LineTo(xc+xp3*llength,yc-yp3*llength);
Ellipse(xp3*llength+xc-point_size,yc-yp3*llength-point_size,
xc+xp3*llength+point_size,yc-yp3*llength+point_size);
MoveTo(xp3*llength+xc,yc-yp3*llength);
LineTo(xc+xp1*llength,yc-yp1*llength);
end;
end;
procedure TForm1.Button6Click(Sender: TObject);
var
xp1,yp1,xp2,yp2,xp3,yp3:integer;
point_size:integer;
a,b,c,d,n,m:double;
begin
Button5.Click;
//draw_axises();
point_size:=2;
a:=strtofloat(LabeledEdit19.Text);
b:=strtofloat(LabeledEdit20.Text);
c:=strtofloat(LabeledEdit21.Text);
d:=strtofloat(LabeledEdit22.Text);
m:=strtofloat(LabeledEdit25.Text);
n:=strtofloat(LabeledEdit26.Text);
xp1:=strtoint(LabeledEdit15.Text);
yp1:=strtoint(LabeledEdit17.Text);
xp2:=strtoint(LabeledEdit16.Text);
yp2:=strtoint(LabeledEdit18.Text);
xp3:=strtoint(LabeledEdit23.Text);
yp3:=strtoint(LabeledEdit24.Text);
xp1:=round(xp1*a+yp1*c+m);
yp1:=round(xp1*b+yp1*d+n);
xp2:=round(xp2*a+yp2*c+m);
yp2:=round(xp2*b+yp2*d+n);
xp3:=round(xp3*a+yp3*c+m);
yp3:=round(xp3*b+yp3*d+n);
with PaintBox1.Canvas do
begin
Pen.Color:=clGreen;
Ellipse(xp1*llength+xc-point_size,yc-yp1*llength-point_size,
xc+xp1*llength+point_size,yc-yp1*llength+point_size);
MoveTo(xp1*llength+xc,yc-yp1*llength);
LineTo(xc+xp2*llength,yc-yp2*llength);
Ellipse(xp2*llength+xc-point_size,yc-yp2*llength-point_size,
xc+xp2*llength+point_size,yc-yp2*llength+point_size);
MoveTo(xp2*llength+xc,yc-yp2*llength);
LineTo(xc+xp3*llength,yc-yp3*llength);
Ellipse(xp3*llength+xc-point_size,yc-yp3*llength-point_size,
xc+xp3*llength+point_size,yc-yp3*llength+point_size);
MoveTo(xp3*llength+xc,yc-yp3*llength);
LineTo(xc+xp1*llength,yc-yp1*llength);
end;
end;
end.
Висновок: На даній лабораторній роботі я ознайомився з основами комп`ютерної графіки.