Einzelnen Beitrag anzeigen

Benutzerbild von Bummi
Bummi

Registriert seit: 15. Jun 2010
Ort: Augsburg Bayern Süddeutschland
3.470 Beiträge
 
Delphi XE3 Enterprise
 
#9

AW: Kreis zeichnen, Pie?

  Alt 11. Apr 2012, 12:52
Delphi-Quellcode:
type
TSegInfo=Record
   Value:Double;
   Color:TColor;
End;
TDarray=Array of TSegInfo;

Procedure Torte(C:TCanvas; X,Y,Radius:Integer;a:TDarray);
var
 i:Integer;
 s:Double;
 v,lv:Double;
begin
  s := 0;
  lv := 0;
  for i := Low(a) to High(a) do s := s + a[i].Value;
  for i := Low(a) to High(a) do
    begin
      v := lv + a[i].Value;
      C.Brush.Color := a[i].Color;
      C.Pie(X,Y,X+Radius*2,y+Radius*2, X + Radius + Round(( Radius * cos(V/s * 2 * PI))) ,y + Radius + Round(( Radius * sin(V/s * 2 * PI)))
                   , X + Radius + Round(( Radius * cos(LV/s * 2 * PI))) ,y + Radius + Round(( Radius * sin(LV/s * 2 * PI))) );
      lv := v;
    end;

end;


procedure TForm2.Button1Click(Sender: TObject);
var
 a:TDarray;
begin
   SetLength(a,3);
   a[0].Value := 100;
   a[1].Value := 50;
   a[2].Value := 25;
   a[0].Color := clRed;
   a[1].Color := clLime;
   a[2].Color := clBlue;

   Torte(Canvas,10,10,200,a)

end;
Thomas Wassermann H₂♂
Das Problem steckt meistens zwischen den Ohren
DRY DRY KISS
H₂ (wenn bei meinen Snipplets nichts anderes angegeben ist Lizenz: WTFPL)
  Mit Zitat antworten Zitat