Thema: Delphi Pendel Simulation

Einzelnen Beitrag anzeigen

EWeiss
(Gast)

n/a Beiträge
 
#1

Pendel Simulation

  Alt 29. Mär 2015, 18:01
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

Geändert von EWeiss (11. Jul 2019 um 15:42 Uhr)
  Mit Zitat antworten Zitat