|
Вопрос # 6 130/ вопрос открыт / |
|
Здравствуйте!)
Мне нужна помощь в понимании программы в Дэлфи! Необходимо прокоментировать листинг программы! Чем больше строчек прокоментируете, тем больше поможете!
Буду очень-очень благодарна!=\
Большое спасибо!)
Приложение: Переключить в обычный режим- unit AffinPlaneUnit_v;
- interface
- uses
- Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
- Dialogs, ComCtrls, StdCtrls, ExtCtrls, Spin, Buttons,Math;
- type
- // Matrix= array[0..2,0..2] of real ;//integer;
- // Stroka= array[0..2] of real;
- Stroka= array[0..2] of extended;
- Matrix= array[0..2] of stroka;
- AP=array[1..3] of extended;
- MAP=array[1..3] of AP;
- TAffinPlaneForm = class(TForm)
- GroupBox1: TGroupBox;
- MainImage: TImage;
- LocGrBox: TGroupBox;
- X0Lbl: TLabel;
- Y0Lbl: TLabel;
- X0Edit: TEdit;
- Y0Edit: TEdit;
- X0UpDown: TUpDown;
- Y0UpDown: TUpDown;
- RotGB: TGroupBox;
- BoxModify: TComboBox;
- GrPoly: TGroupBox;
- Lcord1: TLabel;
- Lcord2: TLabel;
- Lcord3: TLabel;
- Lcord4: TLabel;
- Lcord5: TLabel;
- Lcord6: TLabel;
- Lcord7: TLabel;
- Lcord8: TLabel;
- Sx1: TSpinEdit;
- Sy1: TSpinEdit;
- Sx2: TSpinEdit;
- Sy2: TSpinEdit;
- Sx3: TSpinEdit;
- Sy3: TSpinEdit;
- Sx4: TSpinEdit;
- Sy4: TSpinEdit;
- RotateSpin: TSpinEdit;
- GrRel: TRadioGroup;
- ScaleGB: TGroupBox;
- KXSpin: TSpinEdit;
- KYSpin: TSpinEdit;
- Label3: TLabel;
- Label4: TLabel;
- MirGB: TGroupBox;
- OXCB: TCheckBox;
- OYCB: TCheckBox;
- ShiftGB: TGroupBox;
- KxShiftSpin: TSpinEdit;
- KyShiftSpin: TSpinEdit;
- Label1: TLabel;
- Label2: TLabel;
- Button5: TButton;
- Label5: TLabel;
- Label6: TLabel;
- Button1: TButton;
- procedure ReNew();
- procedure FormCreate(Sender: TObject);
- function MMul(A:Matrix;X:Stroka):Stroka;
- procedure Move(Add:integer=0);
- function Trans(M:Matrix):Matrix;
- procedure Rotate(Add:integer=0);
- procedure BoxModifyChange(Sender: TObject);
- procedure Y0UpDownClick(Sender: TObject; Button: TUDBtnType);
- procedure GrRelClick(Sender: TObject);
- procedure Scale();
- procedure Mirror();
- procedure Shift();
- procedure Sx1Change(Sender: TObject);
- procedure Button5Click(Sender: TObject);
- procedure Button6Click(Sender: TObject);
- procedure Button1Click(Sender: TObject);
- // procedure Button6Click(Sender: TObject);
- // procedure Button6Click(Sender: TObject);
- private
- { Private declarations }
- public
- { Public declarations }
- end;
- var
- AffinPlaneForm: TAffinPlaneForm;
- S1,S2:Stroka;
- Fig: stroka;
- Coord: array[0..3] of stroka;
- Beg: array[0..3] of stroka;
- const
- One:matrix=((1,0,0),(0,1,0),(0,0,1));
- implementation
- {$R *.dfm}
- procedure TAffinPlaneForm.ReNew();
- var
- dl: integer;
- hi,i: integer;
- jk:integer;
- begin
- dl := MainImage.Width;
- hi := MainImage.Height;
- i := 0;
- with MainImage.Canvas do
- begin
-
- Rectangle(0,0,MainImage.ClientWidth+1,MainImage.ClientHeight+1);
- Brush.Style := bsClear;
-
- Pen.Color := clMoneyGreen;
- while (i<dl-1) do
- begin
- MoveTo(i,0);
- LineTo(i,402);
- i := i + 10;
- end;
- i := 0;
- while (i<hi-1) do
- begin
- MoveTo(0,i);
- LineTo(402,i);
- i := i + 10;
- end;
- Pen.Color := clMaroon;
- Pen.Style := psSolid;
-
- MoveTo(201,0);
- LineTo(201,402);
- MoveTo(0,201);
- LineTo(402,201);
-
- MoveTo(201,0);
- LineTo(198,10);
- MoveTo(201,0);
- LineTo(204,10);
- TextOut(210,1,'y');
-
- MoveTo(402,201);
- LineTo(392,198);
- MoveTo(402,201);
- LineTo(392,204);
- TextOut(393,201,'x');
-
- Pen.Color := clHotLight;
- Brush.Style := bsClear;
- MoveTo(Trunc(Sx1.Value + 201),Trunc(-Sy1.Value + 201));
- LineTo(Trunc(Sx2.Value + 201),Trunc(-Sy2.Value + 201));
- LineTo(Trunc(Sx3.Value + 200),Trunc(-Sy3.Value + 201));
- LineTo(Trunc(Sx4.Value + 200),Trunc(-Sy4.Value + 201));
- LineTo(Trunc(Sx1.Value + 201),Trunc(-Sy1.Value + 201));
- for i:=0 to 3 do
- TextOut(TSpinEdit(GrPoly.FindChildControl('Sx'+IntToStr(i+1))).Value +
201,-TSpinEdit(GrPoly.FindChildControl('Sy'+IntToStr(i+1))).Value+201,IntToStr(TSpinEdit(GrPoly.FindChildControl('Sx'+IntToStr(i+1))).Value)+';'+IntToStr(TSpinEdit(GrPoly.FindChildControl('Sy'+IntToStr(i+1))).Value));
- if GrRel.ItemIndex=1 then
- begin
- Pen.Color := clWhite;
- MoveTo(0,201-StrToInt(Y0Edit.Text)-1);
- LineTo(402,201-StrToInt(Y0Edit.Text)-1);
- MainImage.Canvas.Pen.Color := clGreen;
- MoveTo(0,201-StrToInt(Y0Edit.Text));
- LineTo(402,201-StrToInt(Y0Edit.Text));
- MainImage.Canvas.Pen.Color := clWhite;
- MoveTo(201+StrToInt(X0Edit.Text)-1,0);
- LineTo(201+StrToInt(X0Edit.Text)-1,402);
- MainImage.Canvas.Pen.Color := clGreen;
- MoveTo(201+StrToInt(X0Edit.Text),0);
- LineTo(201+StrToInt(X0Edit.Text),402);
- end;
- Pen.Color := clRed;
- Brush.Style := bsClear;
- MoveTo(Trunc(Coord[0,0] + 201),Trunc(-Coord[0,1] + 201));
- LineTo(Trunc(Coord[1,0] + 201),Trunc(-Coord[1,1] + 201));
- LineTo(Trunc(Coord[2,0] + 200),Trunc(-Coord[2,1] + 201));
- LineTo(Trunc(Coord[3,0] + 200),Trunc(-Coord[3,1] + 201));
- LineTo(Trunc(Coord[0,0] + 201),Trunc(-Coord[0,1] + 201));
- Brush.Color:=clMaroon;
- for i:=0 to 3 do
- Ellipse(Trunc(Coord[i,0] + 199),Trunc(-Coord[i,1] + 199),Trunc(Coord[i,0] +
203),Trunc(-Coord[i,1] + 203));
- Brush.Style := bsClear;
- for i:=0 to 3 do
- TextOut(Trunc(Coord[i,0] + 201),Trunc(-Coord[i,1] +
201),IntToStr(Trunc(Coord[i,0]))+';'+IntToStr(Trunc(Coord[i,1])));
- end;
- end;
- procedure TAffinPlaneForm.FormCreate(Sender: TObject);
- var
- i: integer;
- begin
- for i:=0 to 3 do
- begin
- Coord[i,0] := TSpinEdit(GrPoly.FindChildControl('Sx'+intToStr(i+1))).Value;
- Coord[i,1] := TSpinEdit(GrPoly.FindChildControl('Sy'+intToStr(i+1))).Value;
- Coord[i,2] := 1;
- Beg[i,0] := TSpinEdit(GrPoly.FindChildControl('Sx'+intToStr(i+1))).Value;
- Beg[i,1] := TSpinEdit(GrPoly.FindChildControl('Sy'+intToStr(i+1))).Value;
- Beg[i,2] := 1;
- end;
- ReNew();
- end;
- function TAffinPlaneForm.Trans(M:Matrix):Matrix;
- var
- Temp : Matrix;
- i,j: integer;
- begin
- Temp := M;
- for i:=0 to 2 do
- for j:=0 to 2 do
- M[j,i] := Temp[i,j];
- Result := M;
- end;
- function TAffinPlaneForm.MMul(A:Matrix;X:Stroka):Stroka;
- var
- Res:stroka;
- i,j:integer;
- begin
- for i:=0 to 2 do
- Res[i]:=0;
- for j:=0 to 2 do
- for i:=0 to 2 do
- Res[j]:=Res[j]+A[i][j]*X[i];
- Result:=Res;
- end;
- procedure TAffinPlaneForm.Move(Add:integer=0);
- var
- i:integer;
- A:matrix;
- begin
- A:=One;
- if Add=0 then
- begin
- A[0,2] := StrToInt(X0edit.Text);
- A[1,2] := StrToInt(Y0edit.Text);
- end
- else
- begin
- A[0,2] := -StrToInt(X0edit.Text);
- A[1,2] := -StrToInt(Y0edit.Text);
- end ;
- A := Trans(A);
- for i:=0 to 3 do
- if GrRel.ItemIndex=1 then
- Coord[i]:=MMul(A,Coord[i])//Beg[i]);
- else
- Coord[i]:=MMul(A,Beg[i]);
- end;
- procedure TAffinPlaneForm.Rotate(Add:integer=0);
- var
- i:integer;
- A:Matrix;
- begin
- A:=One;
- A[0][0]:=cos(DegToRad(RotateSpin.Value));
- A[0][1]:=-sin(DegToRad(RotateSpin.Value));
- A[1][0]:=sin(DegToRad(RotateSpin.Value));
- A[1][1]:=cos(DegToRad(RotateSpin.Value));
- A := Trans(A);
- if GrRel.ItemIndex=1 then
- Move(1);
- for i:=0 to 3 do
- Coord[i]:=MMul(A,Coord[i]);
- if GrRel.ItemIndex=1 then
- Move();
- end;
- procedure TAffinPlaneForm.Scale();
- var
- i:integer;
- A:Matrix;
- begin
- A:=One;
- A[0][0]:= KXSpin.Value*0.1;
- A[1][1]:= KYSpin.Value*0.1;
- A := Trans(A);
- if GrRel.ItemIndex=1 then
- Move(1);
- for i:=0 to 3 do
- Coord[i]:=MMul(A,Coord[i]);
- if GrRel.ItemIndex=1 then
- Move();
- end;
- procedure TAffinPlaneForm.Mirror();
- var
- i:integer;
- A:Matrix;
- begin
- A:=One;
- if OXCB.Checked then
- A[0][0]:=-1;
- if OYCB.Checked then
- A[1][1]:=-1;
- A := Trans(A);
- if GrRel.ItemIndex=1 then
- Move(1);
- for i:=0 to 3 do
- Coord[i]:=MMul(A,Coord[i]);
- if GrRel.ItemIndex=1 then
- Move();
- end;
- procedure TAffinPlaneForm.Shift();
- var
- i:integer;
- A: Matrix;
- begin
- A:=One;
- A[0][1]:=KxShiftSpin.Value*0.1;
- A[1][0]:=KyShiftSpin.Value*0.1;
- A := Trans(A);
- if GrRel.ItemIndex=1 then
- Move(1);
- for i:=0 to 3 do
- Coord[i]:=MMul(A,Coord[i]);
- if GrRel.ItemIndex=1 then
- Move();
- end;
- procedure TAffinPlaneForm.BoxModifyChange(Sender: TObject);
- var
- i:integer;
- begin
- ReNew();
- RotateSpin.Value := 0;
- for i:=0 to 3 do
- Beg[i] := Coord[i];
- GrRel.ItemIndex := 0;
- case BoxModify.ItemIndex of
- 0: begin
- LocGrBox.Enabled := True;
- RotGB.Enabled := False;
- GrRel.ItemIndex := 0;
- GrRel.Enabled := False;
- ScaleGB.Enabled := False;
- MirGB.Enabled := False;
- ShiftGB.Enabled := False;
- MainImage.Canvas.Pen.Color := clWhite;
-
- MainImage.Canvas.MoveTo(0,201-StrToInt(Y0Edit.Text));
- MainImage.Canvas.LineTo(402,201-StrToInt(Y0Edit.Text));
- MainImage.Canvas.MoveTo(201+StrToInt(X0Edit.Text),0);
- MainImage.Canvas.LineTo(201+StrToInt(X0Edit.Text),402);
- ReNew();
- //
- end;
- 1: begin
- LocGrBox.Enabled := False;
- MirGB.Enabled := False;
- ScaleGB.Enabled := False;
- ShiftGB.Enabled := False;
- RotGB.Enabled := True;
- GrRel.Enabled := True;
-
- end;
- 2: begin
- LocGrBox.Enabled := False;
- RotGB.Enabled := False;
- MirGB.Enabled := False;
- ShiftGB.Enabled := False;
- ScaleGB.Enabled := True;
- GrRel.Enabled := True;
- end;
- 3: begin
- LocGrBox.Enabled := False;
- RotGB.Enabled := False;
- ScaleGB.Enabled := False;
- ShiftGB.Enabled := False;
- MirGB.Enabled := True;
- GrRel.Enabled := True;
- end;
- 4: begin
- LocGrBox.Enabled := False;
- RotGB.Enabled := False;
- ScaleGB.Enabled := False;
- MirGB.Enabled := False;
- ShiftGB.Enabled := True;
- GrRel.Enabled := True;
- end;
- end;
- X0Edit.Text:='0';
- Y0Edit.Text:='0';
- end;
- procedure TAffinPlaneForm.Y0UpDownClick(Sender: TObject;
- Button: TUDBtnType);
- begin
- if GrRel.ItemIndex=0 then
- begin
-
- X0Lbl.Caption := 'X:';
- Y0Lbl.Caption := 'Y:';
- MainImage.Canvas.Pen.Color := clRed;
- Move();
- ReNew();
- end
- else
- begin
-
- X0Lbl.Caption := 'X0:';
- Y0Lbl.Caption := 'Y0:';
- ReNew();
- if GrRel.ItemIndex=1 then
- begin
- MainImage.Canvas.Pen.Color := clWhite;
- with MainImage.Canvas do
- begin
- MoveTo(0,201-StrToInt(Y0Edit.Text)-1);
- LineTo(402,201-StrToInt(Y0Edit.Text)-1);
- MainImage.Canvas.Pen.Color := clGreen;
- MoveTo(0,201-StrToInt(Y0Edit.Text));
- LineTo(402,201-StrToInt(Y0Edit.Text));
-
- MainImage.Canvas.Pen.Color := clWhite;
- MoveTo(201+StrToInt(X0Edit.Text)-1,0);
- LineTo(201+StrToInt(X0Edit.Text)-1,402);
- MainImage.Canvas.Pen.Color := clGreen;
- MoveTo(201+StrToInt(X0Edit.Text),0);
- LineTo(201+StrToInt(X0Edit.Text),402);
- end
- end
- end;
- ReNew();
- end;
- procedure TAffinPlaneForm.GrRelClick(Sender: TObject);
- begin
- if GrRel.ItemIndex=0 then
- begin
-
- X0Lbl.Caption := 'X:';
- Y0Lbl.Caption := 'Y:';
- if BoxModify.ItemIndex<>0 then LocGrBox.Enabled := False;
- end
- else
- begin
- LocGrBox.Enabled := True;
-
- X0Lbl.Caption := 'X0:';
- Y0Lbl.Caption := 'Y0:';
- X0Edit.Text := '0';
- Y0Edit.Text := '0';
- end;
- ReNew();
- end;
- procedure TAffinPlaneForm.Sx1Change(Sender: TObject);
- var
- i:integer;
- begin
- for i:=0 to 3 do
- begin
- Coord[i,0] := TSpinEdit(GrPoly.FindChildControl('Sx'+intToStr(i+1))).Value;
- Coord[i,1] := TSpinEdit(GrPoly.FindChildControl('Sy'+intToStr(i+1))).Value;
- Coord[i,2] := 1;
- Beg[i,0] := TSpinEdit(GrPoly.FindChildControl('Sx'+intToStr(i+1))).Value;
- Beg[i,1] := TSpinEdit(GrPoly.FindChildControl('Sy'+intToStr(i+1))).Value;
- Beg[i,2] := 1;
- end;
- ReNew();
- end;
- procedure TAffinPlaneForm.Button5Click(Sender: TObject);
- begin
- GrPoly.Enabled := False;
- MainImage.Canvas.Pen.Color := clRed;
- case BoxModify.ItemIndex of
- 1:Rotate();
- 2:Scale();
- 3:Mirror();
- 4:Shift();
- end;
- ReNew();
- end;
- procedure TAffinPlaneForm.Button6Click(Sender: TObject);
- begin
- if GrRel.ItemIndex=0 then
- begin
-
- X0Lbl.Caption := 'X:';
- Y0Lbl.Caption := 'Y:';
- MainImage.Canvas.Pen.Color := clRed;
- Move();
- ReNew();
- end
- else
- begin
-
- X0Lbl.Caption := 'X0:';
- Y0Lbl.Caption := 'Y0:';
- ReNew();
- if GrRel.ItemIndex=1 then
- begin
- MainImage.Canvas.Pen.Color := clWhite;
- with MainImage.Canvas do
- begin
- MoveTo(0,201-StrToInt(Y0Edit.Text)-1);
- LineTo(402,201-StrToInt(Y0Edit.Text)-1);
- MainImage.Canvas.Pen.Color := clGreen;
- MoveTo(0,201-StrToInt(Y0Edit.Text));
- LineTo(402,201-StrToInt(Y0Edit.Text));
- MainImage.Canvas.Pen.Color := clWhite;
- MoveTo(201+StrToInt(X0Edit.Text)-1,0);
- LineTo(201+StrToInt(X0Edit.Text)-1,402);
- MainImage.Canvas.Pen.Color := clGreen;
- MoveTo(201+StrToInt(X0Edit.Text),0);
- LineTo(201+StrToInt(X0Edit.Text),402);
- end
- end
- end;
- ReNew();
- end;
- procedure TAffinPlaneForm.Button1Click(Sender: TObject);
- var
- i: integer;
- begin
- X0Edit.Text := '0';
- Y0Edit.Text := '0';
- RotateSpin.Value := 0;
- KXSpin.Value := 0;
- KYSpin.Value := 0;
- OYCB.Checked := False;
- OXCB.Checked := False;
- KXShiftSpin.Value := 0;
- KYShiftSpin.Value := 0;
- GrRel.ItemIndex := 0;
- Sx1.Value := 0; Sy1.Value := 0;
- Sx2.Value := 0; Sy2.Value := 100;
- Sx3.Value := 100; Sy3.Value := 100;
- Sx4.Value := 100; Sy4.Value := 0;
- GrPoly.Enabled := True;
- for i:=0 to 3 do
- begin
- Coord[i,0] := TSpinEdit(GrPoly.FindChildControl('Sx'+intToStr(i+1))).Value;
- Coord[i,1] := TSpinEdit(GrPoly.FindChildControl('Sy'+intToStr(i+1))).Value;
- Coord[i,2] := 1;
- Beg[i,0] := TSpinEdit(GrPoly.FindChildControl('Sx'+intToStr(i+1))).Value;
- Beg[i,1] := TSpinEdit(GrPoly.FindChildControl('Sy'+intToStr(i+1))).Value;
- Beg[i,2] := 1;
- end;
- ReNew();
- end;
- end.
-
 |
Вопрос задала: sone4ko (статус: Посетитель)
Вопрос отправлен: 12 мая 2012, 23:38
Состояние вопроса: открыт, ответов: 0.
|
Мини-форум вопроса
Всего сообщений: 5; последнее сообщение — 13 мая 2012, 22:05; участников в обсуждении: 3.
12 мая 2012, 23:43: Вопрос перемещён из тематического раздела Delphi » Общие вопросы по программированию в раздел Лабораторный практикум » Delphi модератором DNK
|
Толяныч (статус: 4-ый класс), 13 мая 2012, 09:47 [#1]:
По скока за строчку ? Маяковский, шоб строчек было больше, "лесенкой" пис`ал
|
|
min@y™ (статус: Доктор наук), 13 мая 2012, 10:11 [#2]:
Ништяк вопрос! Ставлю 5 баллов.
Слышь, красавица, а почему ты не обратишься с этой просьбой к автору сего кода? Он помер штоль или трубку не берёт?
Почему ты думаешь, что полотенце из 530 строк чужого кода, котрое ты тут вывалила, кто-то будет не то, что комментировать - ЧИТАТЬ?!
Сорри, ничего личного. И тут Фурсенко потрудился.
Делаю лабы и курсачи по Delphi и Turbo Pascal. За ПИВО! Пишите в личку, а лучше в аську. А ещё лучше - звоните в скайп!
|
|
Толяныч (статус: 4-ый класс), 13 мая 2012, 12:38 [#3]:
min@y™: Когда Фурсенко позовет тебя в суд за оскорбление нечеловеческого достоинства, можешь заявлять меня в свидетели защиты. Хоть и из другой дзяржавы
|
|
bugmenot (статус: 3-ий класс), 13 мая 2012, 20:55 [#4]:
Когда сдавать?
виконання програми розпочинається з того самого мiсця, де призупинилося.
|
|
min@y™ (статус: Доктор наук), 13 мая 2012, 22:05 [#5]:
Цитата (Толяныч):
Когда Фурсенко позовет тебя в суд за оскорбление нечеловеческого достоинства, можешь заявлять меня в свидетели защиты. Хоть и из другой дзяржавы
Белорус? Братан, моя мать родилась в Бобруйске!
Цитата (bugmenot):
Когда сдавать?
Вчера, наверное...
Делаю лабы и курсачи по Delphi и Turbo Pascal. За ПИВО! Пишите в личку, а лучше в аську. А ещё лучше - звоните в скайп!
|
Чтобы оставлять сообщения в мини-форумах, Вы должны авторизироваться на сайте.
|