ich versuche nen Tacho zu programieren.
Ansich funzt er auch nur gibt es da ein Problem auf Wince.
Folgender Code ist zum Zeichnen der Pfeile:
Code: Alles auswählen
rocedure ZeichnePfeil(Can: TCanvas; Col : TColor; SLange,Beta : Byte; Filled : Boolean; P1, P2: TPoint);
//created by Christof Urbaczek
function GetDEG(Winkel: Extended): Extended; // Winkel ins Gradmaß
begin
Result := (Winkel * 2 * Pi) / 360;
end;
function GetRAD(Winkel: Extended): Extended; // Winkel im Winkelmaß
begin
Result := (Winkel * 360) / (2 * Pi);
end;
var
Punkte: array [0..2] of TPoint; // Array für die Punkte der Pfeilspitze
Alpha, AlphaZ: Extended; // Winkel zur horizontalen Achse durch P1
begin
//Farben einstellen
Can.Brush.Color := Col;
Can.Pen.Color := Col;
//Linie zeichnen
Can.Pen.Style := psSolid;
Can.MoveTo(P1.X, P1.Y);
Can.LineTo(P2.X, P2.Y);
//Pfeilspitze (1.Punkt)
Punkte[0].X := P2.X;
Punkte[0].Y := P2.Y;
//Winkel ermitteln
Alpha := 0;
if P2.X = P1.X then
AlphaZ := 0
else
AlphaZ := GetRAD(ArcTan((P2.Y - P1.Y) / (P2.X - P1.X)));
if (P2.X > P1.X) and (P2.Y = P1.Y) then Alpha := 0
else if (P2.X > P1.X) and (P2.Y < P1.Y) then Alpha := 0 - AlphaZ
else if (P2.X = P1.X) and (P2.Y < P1.Y) then Alpha := 90
else if (P2.X < P1.X) and (P2.Y < P1.Y) then Alpha := 180 - AlphaZ
else if (P2.X < P1.X) and (P2.Y = P1.Y) then Alpha := 180
else if (P2.X < P1.X) and (P2.Y > P1.Y) then Alpha := 180 - AlphaZ
else if (P2.X = P1.X) and (P2.Y > P1.Y) then Alpha := 270
else if (P2.X > P1.X) and (P2.Y > P1.Y) then Alpha := 360 - AlphaZ;
//2.Punkt
Punkte[1].X := round(P2.X - sLange * cos(GetDEG(Alpha - Beta div 2)));
Punkte[1].Y := round(P2.Y + sLange * sin(GetDEG(Alpha - Beta div 2)));
//3.Punkt
Punkte[2].X := round(P2.X - sLange * cos(GetDEG(Alpha + Beta div 2)));
Punkte[2].Y := round(P2.Y + sLange * sin(GetDEG(Alpha + Beta div 2)));
//Pfeil zeichnen
if Filled then Can.Polygon(Punkte) else begin
Can.MoveTo(Punkte[0].X, Punkte[0].Y);
Can.LineTo(Punkte[1].X, Punkte[1].Y);
Can.MoveTo(Punkte[0].X, Punkte[0].Y);
Can.LineTo(Punkte[2].X, Punkte[2].Y);
end;
end;
Nun werden zwei Pfeile gezeichnet ein Roter der mir die aktuelle Geschwindigkeit anzeigt
und ein Schwarzer der die letzte Geschwindigkeit übermalt.
Leider hat keine der clear Funktionen funktioniert, da gabe es immer irgend welche Irrbilder die man nicht weg bekam,
deshalb der umweg mit dem übermalen.
Code: Alles auswählen
g:=speed*1.825;
b:=112+90*sin((180/80*g+180)*pi/180);
c:=112+90*cos((180/80*g+180)*pi/180);
xkm:=trunc(b);
ykm:=trunc(c);
Zeichnepfeil(image1.canvas,clblack,90,4,true,Point(112,112),Point(ykm1,xkm1));
ZeichnePfeil(Image1.Canvas,clred,90,4,true,Point(112,112),Point(ykm,xkm));
ykm1:=ykm;
xkm1:=xkm;
ich schätze das es an der Fülle von Pfeilen liegen mag.
Auch ein einfügen von doublebuffered brachte keine Verbesserung.
Gibt es eine bessere Lösung oder kann mir jemand einen Tip geben was ich umändern soll damit es laufen könnte.
Bin für jede Hilfe dankbar