AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

Drehpoti zeichnen

Ein Thema von Pinki · begonnen am 30. Mai 2006 · letzter Beitrag vom 31. Mai 2006
Antwort Antwort
Benutzerbild von Pinki
Pinki

Registriert seit: 19. Mai 2006
Ort: Mülheim an der Ruhr
49 Beiträge
 
Delphi 5 Enterprise
 
#1

Drehpoti zeichnen

  Alt 30. Mai 2006, 21:41
Hallo,irgendwie habe ich Knoten im Kopf.Ich möchte ein Drehpoti zeichnen.(Image 40 X 40 Pixel dynamisch)
Zu der Grafik:Aussenradius 20.(Skala)
Drehknopfradius 15.
StartWinkel wählbar von 0-2*Pi in Pi/4 Schritten
Drehwinkel wählbar Pi,3*Pi/2 und 2*Pi
Ich möchte jetzt rundum bzw von StartWinkel bis EndeWinkel alle 45° bzw Pi/4 eine rote LED zeichnen auf folgenden Radianen
RadiusX1:= 19 und radius X2 etwa 16.(Siehe Codeausschnitte)
Delphi-Quellcode:
  StartWinkel := GetStartWinkel(pDat^.NullIndex);
  DrehWinkel := GetDrehWinkel(pDat^.DrehIndex);
  EndeWinkel := StartWinkel - DrehWinkel;
  if EndeWinkel < 0 then EndeWinkel := EndeWinkel + (2 * pi);
Hier kommt die LED Grafik:
Delphi-Quellcode:
        RadiusX1 := (Right-Left+1)*19 div 40 ;
        RadiusY1 := (Bottom-Top+1)*19 div 40 ;
        RadiusX2 := (Right-Left+1)*16 div 40 ;
        RadiusY2 := (Bottom-Top+1)*16 div 40 ;
        LEDWinkel := EndeWinkel;
        //Anzahl der LED´s z.B bei 180° sind es 5 Stück
        If DrehWinkel =Pi then n:=5;
        If DrehWinkel =(3*Pi/2) then n:=7;
        If DrehWinkel =(2*Pi) then n:=8;
        {n:=Trunc(DrehWinkel*4/Pi)+1;}
        DeleteObject(SelectObject(DC,OldPen));
        DeleteObject(SelectObject(DC,OldBrush));
        OldPen := SelectObject(DC,GetStockObject(Black_Pen));
        OldBrush := SelectObject(DC,CreateSolidBrush(clRed));

        for j:=1 to n do
      begin
        //Koordinate der LED
        StartX1 := Trunc(Cos(LEDWinkel)*RadiusX1);
        StartY1 := Trunc(Sin(LEDWinkel)*RadiusY1);
        EndeX1 := Trunc(Cos(LEDWinkel)*RadiusX2);
        EndeY1 := Trunc(Sin(LEDWinkel)*RadiusY2);
        //weil Cos von 90° und 270°=0 X Koordinaten um +-1 verschieben um die Mitte
        if (LEDWinkel=Pi/2) or (LEDWinkel=3*Pi/2) then
        begin
        StartX1:=StartX1+1;
        EndeX1:=EndeX1-1;
        end;
        //weil Sin von 0°,180° und 360°=0 Y Koordinaten um +-1 verschiebenum die Mitte
        if (LEDWinkel=0) or (LEDWinkel=Pi) or (LEDWinkel=2*Pi) then
        begin
        StartY1:=StartY1+1;
        EndeY1:=EndeY1-1;
        end;
        Ellipse(DC,ZentrumX+StartX1,ZentrumY-StartY1,ZentrumX+EndeX1,ZentrumY-EndeY1);
        
        LEDWinkel:=LEDWinkel+(Pi/4);//Winkel um 45° verschieben
        if LEDWinkel>(2*Pi) then LEDWinkel:=LEDWinkel-(2*Pi);
      end;
Die LED bei 0,90°,180° werden nicht dargestellt .Warum???

Grüss
Pinki
*** Cogito ergo sum ***
  Mit Zitat antworten Zitat
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
Benutzerbild von Pinki
Pinki

Registriert seit: 19. Mai 2006
Ort: Mülheim an der Ruhr
49 Beiträge
 
Delphi 5 Enterprise
 
#3

Re: Drehpoti zeichnen

  Alt 31. Mai 2006, 14:34
Vielen Dank Marabu...
Ich habs etwas verändert und angepasst aber die Routine ist sehr gut.

Gibt es eine Funktion mit der ich ein Kreisausschnitt dynamisch färben kann.Ich meine wenn ich jetzt Potizeiger von 0 bis 100% aufdrehe dass der Kreisauschnitt je nach Zeigerstellung am besten von Grün nach Rot dynamisch gefärbt wird?

Vielen Dank im Voraus
Grüss
Pinki

P.S Mit Floodfill und ExFloodFill habe ich versucht sieht nicht so toll aus.
*** Cogito ergo sum ***
  Mit Zitat antworten Zitat
marabu

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

Re: Drehpoti zeichnen

  Alt 31. Mai 2006, 20:50
Ich habe mal den Code für einfarbige Darstellung geschrieben. Wenn du noch eine Skala definierst, dann kannst du die Abschnitte verschiedenfarbig zeichnen:

Delphi-Quellcode:
procedure DrawPercent(img: TImage; n, percent: Integer);
const
  OUTER_OFFSET = 5;
  INNER_OFFSET = 5;
var
  alpha, beta, ro, ri, xa, ya, xb, yb, mx, my: Integer;
begin
  case n of
    5: begin alpha := 180; beta := alpha - Round(percent / 100 * 180); end;
    7: begin alpha := 225; beta := alpha - Round(percent / 100 * 270); end;
    else begin alpha := 270; beta := alpha - Round(percent / 100 * 360); end;
  end;

  mx := Pred(Min(img.Width, img.Height)) shr 1;
  my := mx;
  ro := mx - OUTER_OFFSET;
  ri := INNER_OFFSET;

  with img.Canvas do
  begin
    Pen.Color := clWhite;
    Brush.Color := clGreen;
    xa := mx + Trunc(Cos(DegToRad(alpha)) * ro);
    ya := my - Trunc(Sin(DegToRad(alpha)) * ro);
    xb := mx + Trunc(Cos(DegToRad(beta)) * ro);
    yb := my - Trunc(Sin(DegToRad(beta)) * ro);
    Pie(mx - ro, my - ro, mx + ro, my + ro, xb, yb, xa, ya);
    Brush.Color := clWhite;
    xa := mx + Trunc(Cos(DegToRad(alpha)) * ri);
    ya := my - Trunc(Sin(DegToRad(alpha)) * ri);
    xb := mx + Trunc(Cos(DegToRad(beta)) * ri);
    yb := my - Trunc(Sin(DegToRad(beta)) * ri);
    Pie(mx - ri, my - ri, mx + ri, my + ri, xb, yb, xa, ya);
  end;
end;
Gute Nacht

marabu
  Mit Zitat antworten Zitat
Benutzerbild von Pinki
Pinki

Registriert seit: 19. Mai 2006
Ort: Mülheim an der Ruhr
49 Beiträge
 
Delphi 5 Enterprise
 
#5

Re: Drehpoti zeichnen

  Alt 31. Mai 2006, 21:49
Vilen Dank Marabu.habe selber mit "Pie" probiert hat nicht ganz geklappt.Ich kann ja nicht mit Canvas arbeiten da ich dann nicht in Winswitch Software implementieren kann (Fehlermeldung) sondern mit HDC
Aber das ist dat gleichePie(DC,bla,bla,bla);
werde Morgen mal nach deiner Art versuchen.Ich sag dir Bescheid!
Gute Nacht

Pinki
*** Cogito ergo sum ***
  Mit Zitat antworten Zitat
Antwort Antwort


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 21:11 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