1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
| unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
RadioGroup1: TRadioGroup;
PaintBox1: TPaintBox;
procedure PaintBox1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure PaintBox1MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure Button1Click(Sender: TObject);
procedure RadioGroup1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
b:TBitmap;
dy,dx:integer;
x,y,x1,x2,y1,y2,x3,y3,i,c:integer;
procedure liniya(x1,y1,x2,y2:integer;canvas:Tcanvas);
function sign (dx,dy:integer):integer;
implementation
{$R *.dfm}
function sign (dx,dy:integer):integer;
begin
if dx>0 then result:=1 ;
if dx<0 then result:=-1
else result:=0;
end;
procedure TForm1.PaintBox1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
var
a:array [1..10]of integer;
b:array [1..10]of integer;
begin
if Button=mbLeft then
begin
i:=1;
i:=i+1;
X1:=x;
Y1:=y;
i:=i+1;
PaintBox1.Canvas.LineTo(x1,y1);
PaintBox1.Canvas.MoveTo(x1,y1);
a[i]:=x1;
b[i]:=y1;
i:=i+1;
X1:=x;
Y1:=y;
end;
end;
procedure liniya(x1,y1,x2,y2:integer;canvas:Tcanvas);
begin
if abs(x2-x1)>=abs(y2-y1) then c:=abs(x2-x1)else
c:=abs(y2-y1);
x:=x1+0.5*sign(dx);// ОШИБКА Value assigned to 'sign' never used
y:=y1+0.5*sign(dy);//ОШИБКА Value assigned to 'sign' never used
end;
procedure TForm1.PaintBox1MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
if RadioGroup1.ItemIndex =0 then liniya(x1,y1,x2,y2,PaintBox1.canvas);
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
PaintBox1.Invalidate();
end;
procedure TForm1.RadioGroup1Click(Sender: TObject);
var
a:array [1..10]of integer;
b:array [1..10]of integer;
begin
if RadioGroup1.ItemIndex=0 then
PaintBox1.Canvas.Pen.Color:=clRed;
PaintBox1.Canvas.MoveTo(a[1],b[1]);
PaintBox1.Canvas.LineTo(a[2],b[2]);
for i := 2 to 10 do
begin
if (a[i]OR b[i])<>0 then
begin
//PaintBox1.Canvas.LineTo(a[i],b[i]);
end;
end;
// PaintBox1.Canvas.LineTo(a[1],b[1]);
end;
end. |