Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Multimedia (https://www.delphipraxis.net/16-multimedia/)
-   -   Delphi Pendel Simulation (https://www.delphipraxis.net/184475-pendel-simulation.html)

EWeiss 29. Mär 2015 18:01


Pendel Simulation
 
Hab da so ne Pendel Simulation gebaut..

Da ich mich mit dem direkten zeichnen auf dem Canvas nicht so gut auskenne
wollte ich fragen wie man die Ellipse sauberer zeichnen kann.
Sieht ziemlich grob aus.
Delphi-Quellcode:
procedure TGraph.PrepareScale;
var
  gray: Integer;
begin

  If ScaleMax = 0 Then
    ScaleMax := 1;

  Aspect := Image.Width / Image.Height;

  yMin := -ScaleMax;
  yMax := ScaleMax;
  xMin := -ScaleMax * Aspect;
  xMax := ScaleMax * Aspect;

  Bo := 20;
  BoLeft := Bo;
  BoTop := Bo;
  BoRight := Bo;
  BoBottom := Bo;

  Fact;

  Image.Canvas.brush.Color := $00E0FFFF;
  // Hintergrund löschen
  Image.Canvas.FillRect(Image.Canvas.ClipRect);

  gray := 200;
  gray := RGB(gray, gray, gray);
  Image.Canvas.Pen.Color := gray;

  // Koordinatenkreuz
  Image.Canvas.Pen.Mode := pmNotXor;
  Image.Canvas.MoveTo(xxc(xMin), yyc(0));
  Image.Canvas.LineTo(xxc(xMax), yyc(0));
  Image.Canvas.MoveTo(xxc(0), yyc(yMin));
  Image.Canvas.LineTo(xxc(0), yyc(yMax));

  // Brush löschen
  Image.Canvas.Brush.Style:= bsClear;
  // Kreis zeichnen
  DrawEllipseFromCenter(Image.Canvas, xxc(Physics.x0), yyc(Physics.y0), trunc(xFact * Physics.L0));

  Image.Canvas.Pen.Color := clblack;
  //Rechteck von links oben nach rechts unten
  Image.Canvas.Rectangle(xxc(xMin), yyc(yMin), xxc(xMax), yyc(yMax));
end;
Delphi-Quellcode:
procedure TGraph.DrawEllipseFromCenter(Canvas: TCanvas; XOffset: integer; YOffset: integer; RadiusOfCircle: Integer);
Var
  R: TRect;
begin

  R.Top := YOffset - RadiusOfCircle;
  R.Left := XOffset - RadiusOfCircle;
  R.Bottom := YOffset + RadiusOfCircle;
  R.Right := XOffset + RadiusOfCircle;
  Canvas.Ellipse(R);
end;
Delphi-Quellcode:
procedure TGraph.Draw;
begin
  Image.Canvas.Font.Color := clblack;
  PrepareScale;

  If Physics.D <> 0 then
  begin
    Image.Canvas.Pen.Color := clblack;
    Image.Canvas.MoveTo(xxc(Physics.x0), yyc(Physics.y0));
    Image.Canvas.LineTo(xxc(Physics.x1), yyc(Physics.y1));
  end;

  Image.Canvas.Brush.Style:= bsSolid;
  Image.Canvas.brush.Color := clblack;
  DrawEllipseFromCenter(Image.Canvas, xxc(Physics.x0), yyc(Physics.y0), trunc(Physics.r0 * xFact));

  Image.Canvas.brush.Color := clred;
  DrawEllipseFromCenter(Image.Canvas, xxc(Physics.x1), yyc(Physics.y1), trunc(Physics.r1 * xFact));

end;
Der rote Klöppel ist sehr unsauber..

gruss

nuclearping 29. Mär 2015 18:05

AW: Pendel Simulation
 
Denke das Stichwort hier ist "Antialiasing".

Bei Google suchendelphi canvas circle antialias

EWeiss 29. Mär 2015 18:21

AW: Pendel Simulation
 
Zitat:

Zitat von nuclearping (Beitrag 1295276)
Denke das Stichwort hier ist "Antialiasing".

Bei Google suchendelphi canvas circle antialias

Gibt's ne alternative ?
Von mir aus sollte auch ein shape ausreichen.

OK Hat sich erledigt habe einfach die Pen-Weite verändert das reicht mir.

gruss


Alle Zeitangaben in WEZ +1. Es ist jetzt 19:13 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz