, . : , , , -. , . - . , , .
pixel (picture element - ) - . , . , . , , : . , , 0 1. , , . . . . , . , . :
,
, , , , . . .
, .
. 30.
, . , . , , , , . . - . . , , , , , .
, ,
.
, . , .
, . , .
, . :
, .
, .
Procedure Bresenham(x1,y1,x2,y2,Color: integer);
var
dx,dy,incr1,incr2,d,x,y,xend: integer;
begin
dx:= ABS(x2-x1);
dy:= Abs(y2-y1);
d:=2*dy-dx; { d}
|
|
incr1:=2*dy; { d<0}
incr2:=2*(dy-dx); { d>=0}
if x1>x2 then { . x}
begin
x:=x2;
y:=y2;
xend:=x1;
end
else
begin
x:=x1;
y:=y1;
xend:=x2;
end;
PutPixel(x,y,Color); { }
While x<xend do
begin
x:=x+1;
if d<0 then
d:=d+incr1 { }
else
begin
y:=y+1;
d:=d+incr2; { , y-}
end;
PutPixel(x,y,Color);
end;{while}
end;{procedure}
, , , , . , , , , , . . , , . , . , , , . - , . :
.
, . , . x ,
- . , , , .
, . 31.
0000. 4- / . 1 .
1 - ;
2 ;
3 - ;
4 - ;
. : - 1- , - 2- , - 3- - 4- . , , 0000, , . , , . 1 , . 0000, , . , / , . .
|
|
, . , , : xmin, xmax, ymin, ymax. : Accept_Check ; Reject_Check ; Outcodes 4- /; SWAP .
Procedure CLIP(x1,x2,y1,y2,xmin,xmax,ymin,ymax: real);
type
outcode = array[1..4] of boolean;
var
accept,reject,done: boolean;
outcode1,outcode2,
outcode3,outcode4:outcode;{ /}
begin
accept:= false;
reject:= false;
done:= false;
repeat
Outcodes(x1,y1,outcode1);
Outcodes(x2,y2,outcode2);
{ }
reject:=Reject_Check(outcode1,outcode2);
if reject then done:= true
else
begin { }
accept:=Accept_Check(outcode1,outcode2);
if accept then done:=true
else
begin { }
{ P1 , SWAP }
if not((outcode1[1])or(outcode1[2])or
(outcode1[3])or(outcode1[4])) then SWAP;
{ P1 }
if outcode1[1] then
begin { }
x1:=x1+(x2-x1)*(ymax-y1)/(y2-y1);
y1:=ymax;
end
else if outcode1[2] then
if outcode1[1] then
begin { }
x1:=x1+(x2-x1)*(ymin-y1)/(y2-y1);
y1:=ymin;
end
else if outcode1[3] then
begin { }
y1:=x1+(y2-y1)*(ymax-x1)/(x2-x1);
x1:=xmax;
end
else if outcode1[4] then
begin { }
y1:=x1+(y2-y1)*(ymin-x1)/(x2-x1);
x1:=xmin;
end;
end;
end;
until done;
if accept then
Line(x1,y1,x2,y2); { }
end;{procedure}