Algorytm Bresenhama

Rysowanie linii (odcinka) przechodząca przez dwa punkty o współrzędnych P1(x1,y1) i P2(x2,y2) procedura w języku Pascal

 Procedure Linia(x1,y1,x2,y2,Kolor : integer);
 var c,i : integer;
    sx,sy,y,x : real;
  begin
 { if x2<x1 then begin   {ten warunek nie pozwala rysowac linii 'wygladajacej jak funkcja rosnaca'!!!} 
   c:=x1;
   x1:=x2;
   x2:=c;
  end;
  if y2<y1 then begin
   c:=y2;
   y2:=y1;
   y1:=c;
  end; }
  if (x2-x1)>(y2-y1) then begin
    sy:=(y2-y1)/(x2-x1);
    y:=y1;
    for i:=x1 to x2 do begin
      putpixel(i,round(y),Kolor);
      y:=y+sy;
    end;
  end else begin
    sx:=(x2-x1)/(y2-y1);
    x:=x1;
    for i:=y1 to y2 do begin
      putpixel(round(x),i,Kolor);
      x:=x+sx;
    end;
  end;
 end;

Podobne strony

Podobne StronyCałkaAlgorytm PrimaStoperPotegaSizeofPierwszy ProgramNWDIdentyfikatory
Table of Contents
O ile nie zaznaczono inaczej, treść tej strony objęta jest licencją Creative Commons Attribution-ShareAlike 3.0 License