mc_teo
2010-10-17 11:24:34
Right so, this procedure returns a TPA, containing a the points for a nice straight line joining any two TPoints.
As you can see, it is quite mathematical, and therefore slow if you want to update it constantly, to say, draw a line from a constant co-ordinate to the mouses position.
I originally made it to directly manipulate the pixels of bitmaps, but i think it can be added to simba easier this way, to give it a much needed speed boost.
if the name doesnt suit or conflicts feel free to change it.
~mc_teo
As you can see, it is quite mathematical, and therefore slow if you want to update it constantly, to say, draw a line from a constant co-ordinate to the mouses position.
I originally made it to directly manipulate the pixels of bitmaps, but i think it can be added to simba easier this way, to give it a much needed speed boost.
if the name doesnt suit or conflicts feel free to change it.
function PointToPoint(start, finish: TPoint): TPointArray;
var
steep: boolean;
deltax, deltay, error, ystep, x1, y1, len: integer;
TPA: TPointArray;
begin
steep := (iAbs(finish.Y - start.Y) > iAbs(finish.X - start.X));
if steep then
begin
swap(start.X, start.Y);
swap(finish.X, finish.Y);
end;
if start.X > finish.X then
begin
swap(start.X, finish.X);
swap(start.Y, finish.Y);
end;
deltax := (finish.X - start.X);
deltay := iAbs(finish.Y - start.Y);
error := (deltax / 2);
y1 := start.Y
if (start.Y < finish.Y) then
ystep := 1
else
ystep := -1;
for x1 := start.X to finish.X do
begin
if steep then
begin
len := Length(TPA);
SetArrayLength(TPA, len+1);
TPA[len] := Point(y1, x1);
end else
begin
len := Length(TPA);
SetArrayLength(TPA, len+1);
TPA[len] := Point(x1, y1);
end;
error := error - deltay;
if error < 0 then
begin
y1 := y1 + ystep;
error := error + deltax;
end;
end;
Result := TPA;
end;
~mc_teo