Lars Gollub a écrit dans l’article
<6up816$k8u36@forums.borland.com
>…
> >Can you use the fillpoly routine or something like that?
>
> Well, no. This is why I am asking for the algorithm. Windows is
> very slow in drawing *many small* Objects. So I draw them
well, take a look in the good all SWAG ! Von: Paul TOTH
Betreff: Re: Triangle algorithm
Datum: Dienstag, 29. September 1998 08:28
look on my Pascal Page for ZED & BODY.
—
see the triangle as a array of horizontal lines…(or vertical for fast VGA
X-Mode)
0
.
RightX…..LeftX
. A
. BBBB
. CCCCCC
. DDDDDDDD
.
MaxY
[code lang=”delphi”]Var
RightX:array[0..MaxY] of word;
LeftX :array[0..MaxY] of word;
procedure DrawTriangle(color:TColor);
var
x1,x2,y:integer;
begin
for y:=0 to MaxY do begin
x1:=RightX;
x2:=LeftX;
if x1<0 then begin dx:=-dx; ix:=-1 end else ix:=+1;
dy:=y2-y1; if dy<0 then begin dy:=-dy; iy:=-1 end else iy:=+1;
if dx>dy then begin
e1:= 2*dy;
e2:=e1-dx;
e3:=e2-dx;
for i:=0 to dx do begin
if x1LeftSX[y1] then LeftX[y1] :=x1;
inc(x1,ix);
if e2<0 then inc(e2,e1) else begin
inc(e2,e3);
inc(y1,iy);
end;
end;
end else begin
e1:= 2*dx;
e2:=e1-dy;
e3:=e2-dy;
for i:=0 to dy do begin
if x1LeftX[y1] then LeftX[y1] :=x1;
inc(y1,iy);
if e2<0 then inc(e2,e1) else begin
inc(e2,e3);
inc(x1,ix);
end;
end;
end;
end;
procedure Triangle(x1,y1,x2,y2,x3,y3,color:integer);
begin
fillchar(RightX,SizeOf(RightX),255); // default 65535
fillchar(LeftX,SizeOf(LeftX),0); // default 0
scan(x1,y1,x2,y2);
scan(x2,y2,x3,y3);
scan(x3,y3,x1,y1);
DrawTriangle(Color);
end;
[/code]
[tags]Delphi, Graphic[/tags]
0 Kommentare zu “Triangle algorithm”