Programmas kods
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Grids;
type
TForm1 = class(TForm)
butDraw: TButton;
ex1: TEdit;
ey1: TEdit;
ex2: TEdit;
ey2: TEdit;
Label_x: TLabel;
Label_y: TLabel;
tableGrid: TStringGrid;
procedure butDrawClick(Sender: TObject);
procedure swapCoor(var1, var2 : PInteger);
procedure Bresenham(x1, x2, y1, y2 : integer);
procedure writeToGrid(n, Pn, Xn, Yn : integer);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.swapCoor(var1, var2 : PInteger);
var temp : integer;
begin
temp := var1^;
var1^:=var2^;
var2^:=temp;
end;
procedure TForm1.Bresenham(x1, x2, y1, y2 : integer);
var dx, dy, Pn, Xn, Yn, x0, y0, ystep, n : integer;
steep : boolean;
begin
x0:=Round(Form1.Width/2)-100;
y0:=Round(Form1.Height/2)+20;
n:=0;
steep:=abs(x2-x1) < abs(y2-y1);
if (steep=True) then
begin
swapCoor(@x1, @y1);
swapCoor(@x2, @y2);
end;
if (x1 > x2) then
begin
swapCoor(@x1, @x2);
swapCoor(@y1, @y2);
end;
dx:=x2-x1;
dy:=y2-y1;
…