On this page I'd like to introduce U main algorithms, are used in computer graphic. I thought, that it will be interesting not only to real professional at
this area (they have known it before :)) ), but to every delittante programmer. It's interesting to know what compiler do, when it met, for example,the next line
line(-10,-10,100,100);
By the way, here and forward will allege the programm texts, are
written in Pascal. It's the best language for learning programming.
So, the main algorithms :
-
Raster unfold of segment (Algorithm of Bresenham)
-
Raster unfold of segment (Algorithm DDA)
-
Raster unfold of circle (Algorithm of Bresenham)
Another one. Here I am not allege algorithm of clipping. Wait for upgrade my site
procedure lineBres(x1,y1, x2, y2 : integer);
var
x, y, xend, yend, s, dx, dy, d, inc1, inc2 : integer;
begin
dx := abs(x2-x1); dy := abs(y2-y1);
if dx > dy then begin {almost horizontal}
 inc1 := 2*dy; inc2 := 2*(dy - dx); d := 2*dy - dx;
if x1 < x2 then begin
x := x1; y := y1; xend:= x2;
 if y1 < y2 then s := 1
 else s := -1;
end
else begin
x := x2; y := y2; xend := x1;
if y1 > y2 then s := 1
 else s := -1;
end;
putpixel(x, y, cc); {pixel, color ÑÑ}
while x < xend do begin
inc(x);
if d > 0 then begin
inc(y,s);
inc(d, inc2);
end
else inc(d, inc1);
putpixel(x, y, cc);
end
end
else...{the same}
procedure lineBres(x1,y1, x2, y2 : integer);
var
x, y,xend, yend, dx, dy : integer;
k, xf, yf : float; {type float - one of float types}
begin
dx := abs(x2-x1); dy := abs(y2-y1);
if dx > dy then begin {almost horizontal}
k := (y2 - y1)/(x2 - x1);
if x1 < x2 then begin
yf := y1; x := x1; xend := x2;
end
else begin
x := x2; xend := x1; yf := y2;
end;
repeat
putpixel(x, round(yf),cc){put pixel, color ÑÑ}
inc(x); inc(yf, k);
until x > xend;
end
else if dy = 0 then putpixel(x1, y1, cc)
else ... {the same}
Raster unfold of circle(Algorithm of Bresenham)
procedure circle(xc,yc, r : integer);
var
d, x, y : integer;
begin
x := 0; y := r; d := 3 - 2*r;
putpixel8(xc, yc, 0, r); {after one point we can put 7 more}
while x < y do begin
if d <= 0 then
d := d + 4*x + 6
else begin
d := d + 4*(x - y) + 10; dec(y);
end;
inc(x);
putpixel8(xc, yc, x, y);
end;
end;
In preparing this page was used lectures of Ñ.Ç.Ñâåðäëîâà