Thema: Delphi Drehpoti zeichnen

Einzelnen Beitrag anzeigen

marabu

Registriert seit: 6. Apr 2005
10.109 Beiträge
 
#2

Re: Drehpoti zeichnen

  Alt 31. Mai 2006, 07:53
Hi Pinki,

rechne nie mit Float-Werten, wenn du es vermeiden kannst.

Delphi-Quellcode:
uses
  Math;

procedure DrawLeds(img: TImage; n: Integer);
const
  LED_CENTER_OFFSET = 3;
  LED_RADIUS = 2;
var
  alpha, r, x, y, mx, my: Integer;
begin
  case n of
    5: alpha := 180;
    7: alpha := 225;
    else alpha := 270;
  end;

  mx := Pred(Min(img.Width, img.Height)) shr 1;
  my := mx;
  r := mx - LED_CENTER_OFFSET;

  with img.Canvas do
  begin
    Pen.Color := clBlack;
    Brush.Color := clRed;

    while n > 0 do
    begin
      Dec(n);
      x := mx + Trunc(Cos(DegToRad(alpha)) * r);
      y := my - Trunc(Sin(DegToRad(alpha)) * r);
      Ellipse(x - LED_RADIUS, y - LED_RADIUS, x + LED_RADIUS, y + LED_RADIUS);
      Dec(alpha, 45);
    end;
  end;
end;

procedure TDemoForm.ButtonClick(Sender: TObject);
begin
  DrawLeds(Image, 8);
end;
Freundliche Grüße vom marabu
  Mit Zitat antworten Zitat