Mega Code Archive

 
Categories / Delphi / Algorithm Math
 

Bresenhams daire algoritması

var Form1: TForm1; x,y,yaricap:integer; x_mer,y_mer:integer;//x ve y koordinatları için procedure Tform1.daire(x_mer, y_mer,y:integer); var p,x:integer; begin x:=0; y:=yaricap; p:=3-2*yaricap; while x<y do begin Canvas.Pixels[x_mer+x,y_mer+y]:=clyellow;//8 oktan değere göre pixel basar Canvas.Pixels[x_mer-x,y_mer+y]:=clRed; Canvas.Pixels[x_mer+x,y_mer-y]:=clRed; Canvas.Pixels[x_mer-x,y_mer-y]:=clyellow; Canvas.Pixels[x_mer+y,y_mer+x]:=clAqua; Canvas.Pixels[x_mer-y,y_mer+x]:=clHighLight; Canvas.Pixels[x_mer+y,y_mer-x]:=clHighLight; Canvas.Pixels[x_mer-y,y_mer-x]:=clAqua; if p<0 then p:=p+4*x+6 else begin p:=p+4*(x-y)+10; y:=y-1; end; x:=x+1; end; if x=y then begin Canvas.Pixels[x_mer+x,y_mer+y]:=clyellow; Canvas.Pixels[x_mer-x,y_mer+y]:=clRed; Canvas.Pixels[x_mer+x,y_mer-y]:=clRed; Canvas.Pixels[x_mer-x,y_mer-y]:=clyellow; Canvas.Pixels[x_mer+y,y_mer+x]:=clAqua; Canvas.Pixels[x_mer-y,y_mer+x]:=clHighLight; Canvas.Pixels[x_mer+y,y_mer-x]:=clHighLight; Canvas.Pixels[x_mer-y,y_mer-x]:=clAqua; end; end; procedure TForm1.Button1Click(Sender: TObject); begin x_mer:=StrToInt(Edit1.Text); y_mer:=StrToInt(Edit2.text); yaricap:=StrToInt(Edit3.Text); while yaricap>=0 do // for yaricap:=StrToInt(Edit3.Text) downto 0 do begin daire(x_mer,y_mer,yaricap); yaricap:=yaricap-1; end; end; end.