L'algorythme de Bresenham le parcours d'une droite divisée

Contenu du snippet

<pre>
Référence dans wikipédia à L'algorythme de Bresenham.

[https://fr.wikipedia.org/wiki/Algorithme_de_trac%C3%A9_de_segment_de_Bresenham]

{L'algorythme de Bresenham le parcours d'une droite divisé en quatre quartiers de progression}
Procedure Tdbbitmap.Denis_line(a,b,c,d:real; color:tcolorref); {réécrit par denis bertin}
var i,j:integer;
   dx,dy:real;
  begin
  if (a-c)=0 then
  begin {vertical}
  j:=round(a);
  for i:=math.min(round(b),round(d)) to math.max(round(b),round(d)) do
    self.Setpixel(j,i,color);
  exit;
  end; {vertical}
  if (b-d)=0 then
  begin {horizontal}
  j:=round(b);
  for i:=math.min(round(a),round(c)) to math.max(round(a),round(c)) do
  self.Setpixel(i,j,color);
  exit;
  end; {horizontal}
  {delta - différence}
  dx:=(b-d)/(a-c);
  dy:=(a-c)/(b-d);
  if abs(dx)<abs(dy) then
 begin {progression horizontal}
  if a<c then
  begin {quartier 0-45°}
  for i:=round(a) to round(c) do
    begin
    b:=b+dx;
     self.Setpixel(i,round(b),color);
    end
  end {quartier 0-45°}
  else
  begin {quartier 180°-135°}
  for i:=round(c) to round(a) do
    begin
    d:=d+dx;
     self.Setpixel(i,round(d),color);
    end
  end; {quartier 180°-135}
 end {progression horizontal}
  else
 begin {progression vertical}
 if b<d then
  begin {quartier 45°-90°}
  for i:=round(b) to round(d) do
   begin
   a:=a+dy;
    self.Setpixel(round(a),i,color);
   end;
  end {quartier 45°-90°}
 else
  begin {quartier 90°-135°}
  for i:=round(d) to round(b) do
   begin
   c:=c+dy;
    self.Setpixel(round(c),i,color);
   end;
  end; {quartier 90°-135°}
 end; {progression vertical}
end; {denis_line}
</pre>

Compatibilité : Version 1.0

A voir également

Vous n'êtes pas encore membre ?

inscrivez-vous, c'est gratuit et ça prend moins d'une minute !

Les membres obtiennent plus de réponses que les utilisateurs anonymes.

Le fait d'être membre vous permet d'avoir un suivi détaillé de vos demandes et codes sources.

Le fait d'être membre vous permet d'avoir des options supplémentaires.