Einzelnen Beitrag anzeigen

Popov
(Gast)

n/a Beiträge
 
#11

AW: Delphi verändern

  Alt 11. Mai 2015, 20:16
Ich hab zuerst verstanden es geht um die Rechtecklinie.

Egal. Ich hab noch jetzt die alte DrawGradientH Funktion genommen und neue die ColorMix, hab alles in einen Timer gepackt. Fertig ist "The Incredible Delphi-Form Color Show".

Delphi-Quellcode:
procedure DrawGradientH(Canvas: TCanvas; Color1, Color2: TColor; Rect: TRect);
var
  X, R, G, B: Integer;
begin
  for X := Rect.Top to Rect.Bottom do begin
    R := Round(GetRValue(Color1) + ((GetRValue(Color2) - GetRValue(Color1)) *
      X / (Rect.Bottom - Rect.Top)));
    G := Round(GetGValue(Color1) + ((GetGValue(Color2) - GetGValue(Color1)) *
      X / (Rect.Bottom - Rect.Top)));
    B := Round(GetBValue(Color1) + ((GetBValue(Color2) - GetBValue(Color1)) *
      X / (Rect.Bottom - Rect.Top)));

    Canvas.Pen.Color := RGB(R, G, B);
    Canvas.Pen.Width := 1;
    Canvas.Pen.Style := psInsideFrame;

    Canvas.MoveTo(Rect.Left, X);
    Canvas.LineTo(Rect.Right, X);
  end;
end;

function ColorMix(Color1, Color2: TColor; Index, Count: Word): TColor;
var
  R, G, B: Integer;
begin
  if Index > Count then
    Index := Count;

  R := Round(GetRValue(Color1) + ((GetRValue(Color2) - GetRValue(Color1)) *
    Index / Count));
  G := Round(GetGValue(Color1) + ((GetGValue(Color2) - GetGValue(Color1)) *
    Index / Count));
  B := Round(GetBValue(Color1) + ((GetBValue(Color2) - GetBValue(Color1)) *
    Index / Count));

  Result := RGB(R, G, B);
end;

var
  Col1, Col2, Col3, Col4: TColor;

procedure TForm1.Timer1Timer(Sender: TObject);
const
  Count = 100;
begin
  with Sender as TTimer do
  begin
    Interval := 1;

    if Tag = 0 then
    begin
      Col2 := RGB(Random(256), Random(256), Random(256));
      Col4 := RGB(Random(256), Random(256), Random(256));
    end;

    DrawGradientH(Canvas, ColorMix(Col1, Col2, Tag, Count), ColorMix(Col3, Col4, Tag, Count), Canvas.ClipRect);

    Tag := Tag + 1;
    if Tag > Count then
    begin
      Tag := 0;
      Col1 := Col2;
      Col3 := Col4;
    end;
  end;
end;
  Mit Zitat antworten Zitat